test/stringpair_list_test.cc
author Krista Grothoff <krista@pep-project.org>
Mon, 11 Jul 2016 11:41:36 +0200
changeset 830 4d7551272344
child 832 8a54e3a6b155
permissions -rw-r--r--
Added test file for stringpair_list.
     1 #include <stdlib.h>
     2 #include <string.h>
     3 #include "platform.h"
     4 #include <iostream>
     5 #include <fstream>
     6 #include <assert.h>
     7 
     8 #include "stringpair.h"
     9 
    10 using namespace std;
    11 
    12 int test_stringpair_equals(stringpair_t* val1, stringpair_t* val2) {
    13     assert(val1);
    14     assert(val2);
    15     assert(val1->key);
    16     assert(val2->key);
    17     assert(val1->value);
    18     assert(val2->value);
    19     return((strcmp(val1->key, val2->key) == 0) && (strcmp(val1->value, val2->value) == 0));
    20 }
    21 
    22 int main() {
    23     cout << "\n*** data structures: stringpair_list_test ***\n\n";
    24 
    25     const char* val_1_arr[4] = {"I am your father, Luke\n",
    26                                 "These are not the droids you're looking for\n",
    27                                 "Swooping is bad\n",
    28                                 "I should go.\n"};
    29     const char* val_2_arr[4] = {"Had to be me.\n",
    30                                 "Someone else might have gotten it wrong\n",
    31                                 "Na via lerno victoria\n",
    32                                 "I was told that there would be cake.\n"};
    33                                 
    34 //    const stringpair_t* stringpair_arr[4];
    35     
    36     int i;
    37     
    38 //    for (i = 0; i < 4; i++) {
    39 //        stringpair_arr[i] = new stringpair(val_1_arr[i], val_2_arr[i]);
    40 //    }
    41     
    42     cout << "creating one-element stringpair_list...\n";
    43     
    44     stringpair_t* strpair = new_stringpair(val_1_arr[0], val_2_arr[0]);
    45     assert(strpair);
    46     stringpair_list_t* pairlist = new_stringpair_list(strpair);
    47     assert(pairlist->value);
    48     assert(test_stringpair_equals(strpair, pairlist->value));
    49 //    assert(strpair->key != pairlist->value->key);   // test deep copies (to be fixed in next 2 commits)
    50 //    assert(strpair->value != pairlist->value->value);
    51     assert(pairlist->next == NULL);
    52     cout << "one-element stringpair_list created, next element is NULL\n";
    53         
    54     cout << "freeing stringpair_list...\n";
    55     free_stringpair_list(pairlist);
    56     // free_stringpair(strpair); // copy still shallow (to be fixed in next 2 commits);
    57     cout << "done.\n";
    58 
    59     return 0;
    60 }
    61