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