test/stringpair_list_test.cc
changeset 830 4d7551272344
child 832 8a54e3a6b155
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/stringpair_list_test.cc	Mon Jul 11 11:41:36 2016 +0200
     1.3 @@ -0,0 +1,61 @@
     1.4 +#include <stdlib.h>
     1.5 +#include <string.h>
     1.6 +#include "platform.h"
     1.7 +#include <iostream>
     1.8 +#include <fstream>
     1.9 +#include <assert.h>
    1.10 +
    1.11 +#include "stringpair.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +int test_stringpair_equals(stringpair_t* val1, stringpair_t* val2) {
    1.16 +    assert(val1);
    1.17 +    assert(val2);
    1.18 +    assert(val1->key);
    1.19 +    assert(val2->key);
    1.20 +    assert(val1->value);
    1.21 +    assert(val2->value);
    1.22 +    return((strcmp(val1->key, val2->key) == 0) && (strcmp(val1->value, val2->value) == 0));
    1.23 +}
    1.24 +
    1.25 +int main() {
    1.26 +    cout << "\n*** data structures: stringpair_list_test ***\n\n";
    1.27 +
    1.28 +    const char* val_1_arr[4] = {"I am your father, Luke\n",
    1.29 +                                "These are not the droids you're looking for\n",
    1.30 +                                "Swooping is bad\n",
    1.31 +                                "I should go.\n"};
    1.32 +    const char* val_2_arr[4] = {"Had to be me.\n",
    1.33 +                                "Someone else might have gotten it wrong\n",
    1.34 +                                "Na via lerno victoria\n",
    1.35 +                                "I was told that there would be cake.\n"};
    1.36 +                                
    1.37 +//    const stringpair_t* stringpair_arr[4];
    1.38 +    
    1.39 +    int i;
    1.40 +    
    1.41 +//    for (i = 0; i < 4; i++) {
    1.42 +//        stringpair_arr[i] = new stringpair(val_1_arr[i], val_2_arr[i]);
    1.43 +//    }
    1.44 +    
    1.45 +    cout << "creating one-element stringpair_list...\n";
    1.46 +    
    1.47 +    stringpair_t* strpair = new_stringpair(val_1_arr[0], val_2_arr[0]);
    1.48 +    assert(strpair);
    1.49 +    stringpair_list_t* pairlist = new_stringpair_list(strpair);
    1.50 +    assert(pairlist->value);
    1.51 +    assert(test_stringpair_equals(strpair, pairlist->value));
    1.52 +//    assert(strpair->key != pairlist->value->key);   // test deep copies (to be fixed in next 2 commits)
    1.53 +//    assert(strpair->value != pairlist->value->value);
    1.54 +    assert(pairlist->next == NULL);
    1.55 +    cout << "one-element stringpair_list created, next element is NULL\n";
    1.56 +        
    1.57 +    cout << "freeing stringpair_list...\n";
    1.58 +    free_stringpair_list(pairlist);
    1.59 +    // free_stringpair(strpair); // copy still shallow (to be fixed in next 2 commits);
    1.60 +    cout << "done.\n";
    1.61 +
    1.62 +    return 0;
    1.63 +}
    1.64 +