add tests for bloblist_iterate() using C++ lambdas. :-D ENGINE-321
authorRoker <roker@pep-project.org>
Thu, 14 Dec 2017 15:37:16 +0100
branchENGINE-321
changeset 2299e69ea613513f
parent 2298 640f83c07bbd
add tests for bloblist_iterate() using C++ lambdas. :-D
test/bloblist_test.cc
     1.1 --- a/test/bloblist_test.cc	Thu Dec 14 15:20:49 2017 +0100
     1.2 +++ b/test/bloblist_test.cc	Thu Dec 14 15:37:16 2017 +0100
     1.3 @@ -43,6 +43,20 @@
     1.4          && ((!val1->filename && !val2->filename) || (strcmp(val1->filename, val2->filename) == 0)));
     1.5  }
     1.6  
     1.7 +
     1.8 +void iteration_test(bloblist_t* bl)
     1.9 +{
    1.10 +	// no element fulfil predicate -> return NULL
    1.11 +	assert( bloblist_iterate( bl, [](bloblist_t* b) { return b->size == 10000; }) == NULL );
    1.12 +	
    1.13 +	// find one element
    1.14 +	bloblist_t* richtext = bloblist_iterate( bl, [](bloblist_t* b) { return b->mime_type == std::string("text/richtext"); }); 
    1.15 +	assert( richtext );
    1.16 +	assert( richtext->mime_type == std::string("text/richtext"));
    1.17 +	assert( richtext->filename  == std::string("bob.rtf"));
    1.18 +}
    1.19 +
    1.20 +
    1.21  int main() {
    1.22      cout << "\n*** data structures: bloblist_test ***\n\n";
    1.23      char* text1 = strdup("This is just some text.");
    1.24 @@ -98,6 +112,9 @@
    1.25      }
    1.26      assert(p == NULL);
    1.27      
    1.28 +    cout << "\nIteration test\n";
    1.29 +    iteration_test(new_bl);
    1.30 +    
    1.31      cout << "\nduplicating four-element list...\n\n";
    1.32      bloblist_t* duplist = bloblist_dup(new_bl);
    1.33