more tests in. Movin right along. local_cpptest
authorKrista Bennett <krista@pep-project.org>
Thu, 03 May 2018 16:53:26 +0200
branchlocal_cpptest
changeset 2651b05ebb3c2a8d
parent 2650 cafe06d8b209
child 2652 43b913f99a27
more tests in. Movin right along.
test/include/SequenceTests.h
test/include/StringlistTests.h
test/sequence_test.cc
test/src/SuiteMaker.cc
test/src/engine_tests/SequenceTests.cc
test/src/engine_tests/StringlistTests.cc
test/stringlist_test.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/include/SequenceTests.h	Thu May 03 16:53:26 2018 +0200
     1.3 @@ -0,0 +1,19 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#ifndef SEQUENCE_TESTS_H
     1.8 +#define SEQUENCE_TESTS_H
     1.9 +
    1.10 +#include <string>
    1.11 +#include "EngineTestIndividualSuite.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +class SequenceTests : public EngineTestIndividualSuite {
    1.16 +    public:
    1.17 +        SequenceTests(string suitename, string test_home_dir);
    1.18 +    private:
    1.19 +        void check_sequences();
    1.20 +};
    1.21 +
    1.22 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/include/StringlistTests.h	Thu May 03 16:53:26 2018 +0200
     2.3 @@ -0,0 +1,19 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#ifndef STRINGLIST_TESTS_H
     2.8 +#define STRINGLIST_TESTS_H
     2.9 +
    2.10 +#include <string>
    2.11 +#include "EngineTestSuite.h"
    2.12 +
    2.13 +using namespace std;
    2.14 +
    2.15 +class StringlistTests : public EngineTestSuite {
    2.16 +    public:
    2.17 +        StringlistTests(string suitename, string test_home_dir);
    2.18 +    private:
    2.19 +        void check_stringlists();
    2.20 +};
    2.21 +
    2.22 +#endif
     3.1 --- a/test/sequence_test.cc	Thu May 03 16:37:35 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,68 +0,0 @@
     3.4 -// This file is under GNU General Public License 3.0
     3.5 -// see LICENSE.txt
     3.6 -
     3.7 -#include <iostream>
     3.8 -#include <string>
     3.9 -#include <cstring> // for std::strdup()
    3.10 -#include <assert.h>
    3.11 -#include "pEpEngine.h"
    3.12 -
    3.13 -using namespace std;
    3.14 -
    3.15 -int main() {
    3.16 -    cout << "\n*** sequence_test ***\n\n";
    3.17 -
    3.18 -    PEP_SESSION session;
    3.19 -    
    3.20 -    cout << "calling init()\n";
    3.21 -    PEP_STATUS status1 = init(&session);   
    3.22 -    assert(status1 == PEP_STATUS_OK);
    3.23 -    assert(session);
    3.24 -    cout << "init() completed.\n";
    3.25 -
    3.26 -    // sequence test code
    3.27 -
    3.28 -    int32_t value1 = 0;
    3.29 -    char *name1 = strdup("test");
    3.30 -    assert(name1);
    3.31 -    PEP_STATUS status2 = sequence_value(session, name1, &value1);
    3.32 -    assert(status2 == PEP_STATUS_OK);
    3.33 -
    3.34 -    cout << "test sequence: " << value1 << "\n";
    3.35 -
    3.36 -    int32_t value2 = 0;
    3.37 -    PEP_STATUS status3 = sequence_value(session, name1, &value2);
    3.38 -    assert(status3 == PEP_STATUS_OK);
    3.39 -
    3.40 -    cout << "test sequence: " << value2 << "\n";
    3.41 -    assert(value2 == value1 + 1);
    3.42 -//    free(name1);
    3.43 -
    3.44 -    cout << "testing sequence violation\n";
    3.45 -    int32_t value3 = value2;
    3.46 -    PEP_STATUS status4 = sequence_value(session, name1, &value3);
    3.47 -    assert(status4 == PEP_SEQUENCE_VIOLATED);
    3.48 -
    3.49 -    cout << "testing sequence non-violation\n";
    3.50 -    int32_t value4 = value2 + 1;
    3.51 -    PEP_STATUS status5 = sequence_value(session, name1, &value4);
    3.52 -    assert(status5 == PEP_STATUS_OK);
    3.53 -
    3.54 -    cout << "testing UUID generation\n";
    3.55 -    int32_t value5 = 0;
    3.56 -    char name2[37] = { 0, };
    3.57 -    PEP_STATUS status6 = sequence_value(session, name2, &value5);
    3.58 -    assert(status6 == PEP_OWN_SEQUENCE);
    3.59 -    cout << "UUID created: " << name2 << "\n";
    3.60 -
    3.61 -    cout << "set sequence value\n";
    3.62 -    int32_t value6 = value2 + 10;
    3.63 -    PEP_STATUS status7 = sequence_value(session, name1, &value6);
    3.64 -    assert(status7 == PEP_STATUS_OK);
    3.65 -    cout << "value set to " << value6 << "\n";
    3.66 -
    3.67 -    cout << "calling release()\n";
    3.68 -    release(session);
    3.69 -    return 0;
    3.70 -}
    3.71 -
     4.1 --- a/test/src/SuiteMaker.cc	Thu May 03 16:37:35 2018 +0200
     4.2 +++ b/test/src/SuiteMaker.cc	Thu May 03 16:53:26 2018 +0200
     4.3 @@ -15,8 +15,10 @@
     4.4  #include "DecorateTests.h"
     4.5  #include "AppleMailTests.h"
     4.6  #include "CaseAndDotAddressTests.h"
     4.7 +#include "SequenceTests.h"
     4.8  #include "StringpairListTests.h"
     4.9  #include "BloblistTests.h"
    4.10 +#include "StringlistTests.h"
    4.11  #include "TrustwordsTests.h"
    4.12  #include "TrustManipulationTests.h"
    4.13  #include "UserIDAliasTests.h"
    4.14 @@ -26,15 +28,17 @@
    4.15      "DecorateTests",
    4.16      "AppleMailTests",
    4.17      "CaseAndDotAddressTests",
    4.18 +    "SequenceTests",
    4.19      "StringpairListTests",
    4.20      "BloblistTests",
    4.21 +    "StringlistTests",
    4.22      "TrustwordsTests",
    4.23      "TrustManipulationTests",
    4.24      "UserIDAliasTests",
    4.25  };
    4.26  
    4.27  // This file is generated, so magic constants are ok.
    4.28 -int SuiteMaker::num_suites = 8;
    4.29 +int SuiteMaker::num_suites = 10;
    4.30  
    4.31  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    4.32      if (strcmp(test_class_name, "DecorateTests") == 0)
    4.33 @@ -43,10 +47,14 @@
    4.34          *test_suite = new AppleMailTests(test_class_name, test_home);
    4.35      else if (strcmp(test_class_name, "CaseAndDotAddressTests") == 0)
    4.36          *test_suite = new CaseAndDotAddressTests(test_class_name, test_home);
    4.37 +    else if (strcmp(test_class_name, "SequenceTests") == 0)
    4.38 +        *test_suite = new SequenceTests(test_class_name, test_home);
    4.39      else if (strcmp(test_class_name, "StringpairListTests") == 0)
    4.40          *test_suite = new StringpairListTests(test_class_name, test_home);
    4.41      else if (strcmp(test_class_name, "BloblistTests") == 0)
    4.42          *test_suite = new BloblistTests(test_class_name, test_home);
    4.43 +    else if (strcmp(test_class_name, "StringlistTests") == 0)
    4.44 +        *test_suite = new StringlistTests(test_class_name, test_home);
    4.45      else if (strcmp(test_class_name, "TrustwordsTests") == 0)
    4.46          *test_suite = new TrustwordsTests(test_class_name, test_home);
    4.47      else if (strcmp(test_class_name, "TrustManipulationTests") == 0)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/src/engine_tests/SequenceTests.cc	Thu May 03 16:53:26 2018 +0200
     5.3 @@ -0,0 +1,64 @@
     5.4 +// This file is under GNU General Public License 3.0
     5.5 +// see LICENSE.txt
     5.6 +
     5.7 +#include <iostream>
     5.8 +#include <string>
     5.9 +#include <cstring> // for std::strdup()
    5.10 +#include <assert.h>
    5.11 +#include "pEpEngine.h"
    5.12 +
    5.13 +#include "EngineTestSuite.h"
    5.14 +#include "EngineTestIndividualSuite.h"
    5.15 +#include "SequenceTests.h"
    5.16 +
    5.17 +using namespace std;
    5.18 +
    5.19 +SequenceTests::SequenceTests(string suitename, string test_home_dir) : 
    5.20 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
    5.21 +    TEST_ADD(SequenceTests::check_sequences);
    5.22 +}
    5.23 +
    5.24 +void SequenceTests::check_sequences() {
    5.25 +    cout << "\n*** sequence_test ***\n\n";
    5.26 +
    5.27 +    // sequence test code
    5.28 +
    5.29 +    int32_t value1 = 0;
    5.30 +    char *name1 = strdup("test");
    5.31 +    assert(name1);
    5.32 +    PEP_STATUS status2 = sequence_value(session, name1, &value1);
    5.33 +    assert(status2 == PEP_STATUS_OK);
    5.34 +
    5.35 +    cout << "test sequence: " << value1 << "\n";
    5.36 +
    5.37 +    int32_t value2 = 0;
    5.38 +    PEP_STATUS status3 = sequence_value(session, name1, &value2);
    5.39 +    assert(status3 == PEP_STATUS_OK);
    5.40 +
    5.41 +    cout << "test sequence: " << value2 << "\n";
    5.42 +    assert(value2 == value1 + 1);
    5.43 +//    free(name1);
    5.44 +
    5.45 +    cout << "testing sequence violation\n";
    5.46 +    int32_t value3 = value2;
    5.47 +    PEP_STATUS status4 = sequence_value(session, name1, &value3);
    5.48 +    assert(status4 == PEP_SEQUENCE_VIOLATED);
    5.49 +
    5.50 +    cout << "testing sequence non-violation\n";
    5.51 +    int32_t value4 = value2 + 1;
    5.52 +    PEP_STATUS status5 = sequence_value(session, name1, &value4);
    5.53 +    assert(status5 == PEP_STATUS_OK);
    5.54 +
    5.55 +    cout << "testing UUID generation\n";
    5.56 +    int32_t value5 = 0;
    5.57 +    char name2[37] = { 0, };
    5.58 +    PEP_STATUS status6 = sequence_value(session, name2, &value5);
    5.59 +    assert(status6 == PEP_OWN_SEQUENCE);
    5.60 +    cout << "UUID created: " << name2 << "\n";
    5.61 +
    5.62 +    cout << "set sequence value\n";
    5.63 +    int32_t value6 = value2 + 10;
    5.64 +    PEP_STATUS status7 = sequence_value(session, name1, &value6);
    5.65 +    assert(status7 == PEP_STATUS_OK);
    5.66 +    cout << "value set to " << value6 << "\n";
    5.67 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/src/engine_tests/StringlistTests.cc	Thu May 03 16:53:26 2018 +0200
     6.3 @@ -0,0 +1,121 @@
     6.4 +// This file is under GNU General Public License 3.0
     6.5 +// see LICENSE.txt
     6.6 +
     6.7 +#include <stdlib.h>
     6.8 +#include <string.h>
     6.9 +#include "platform.h"
    6.10 +#include <iostream>
    6.11 +#include <fstream>
    6.12 +#include <assert.h>
    6.13 +
    6.14 +#include "stringlist.h"
    6.15 +
    6.16 +#include "EngineTestSuite.h"
    6.17 +#include "EngineTestIndividualSuite.h"
    6.18 +#include "StringlistTests.h"
    6.19 +
    6.20 +using namespace std;
    6.21 +
    6.22 +StringlistTests::StringlistTests(string suitename, string test_home_dir) : 
    6.23 +    EngineTestSuite::EngineTestSuite(suitename, test_home_dir) {            
    6.24 +    TEST_ADD(StringlistTests::check_stringlists);
    6.25 +}
    6.26 +
    6.27 +void StringlistTests::check_stringlists() {
    6.28 +    cout << "\n*** data structures: stringlist_test ***\n\n";
    6.29 +
    6.30 +    const char* str0 = "I am your father, Luke\n";
    6.31 +    
    6.32 +    // new_stringlist test code
    6.33 +    cout << "creating one-element stringlist…\n";
    6.34 +    
    6.35 +    stringlist_t* src = new_stringlist(str0);
    6.36 +    assert(src);
    6.37 +    assert(strcmp(src->value,str0) == 0);
    6.38 +    cout << "Value: " << src->value;
    6.39 +    assert(src->next == NULL);
    6.40 +    cout << "one-element stringlist created, next element is NULL\n";
    6.41 +    
    6.42 +    cout << "freeing stringlist…\n\n";
    6.43 +    free_stringlist(src);
    6.44 +    src = NULL;
    6.45 +    
    6.46 +    // test stringlist_add with four-element list
    6.47 +    cout << "creating four-element stringlist…\n";
    6.48 +    const char* str1 = "String 1";
    6.49 +    const char* str2 = "\tString 2";
    6.50 +    const char* str3 = "\tString 3";
    6.51 +    const char* str4 = "\tString 4\n";
    6.52 +    const char* strarr[4] = {str1, str2, str3, str4};
    6.53 +    cout << "stringlist_add on empty list…\n";
    6.54 +    src = stringlist_add(src, str1); // src is NULL
    6.55 +    assert(src);
    6.56 +    assert(stringlist_add(src, str2)); // returns ptr to new elt
    6.57 +    assert(stringlist_add(src, str3));
    6.58 +    assert(stringlist_add(src, str4));
    6.59 +    
    6.60 +    cout << "checking contents\n";
    6.61 +    stringlist_t* p = src;
    6.62 +    int i = 0;
    6.63 +    while (p) {
    6.64 +        assert(p->value);
    6.65 +        assert(strcmp(p->value, strarr[i++]) == 0);
    6.66 +        assert(p->value != *(strarr + i)); // ensure this is a copy
    6.67 +        cout << p->value;
    6.68 +        p = p->next;
    6.69 +    }
    6.70 +    assert(p == NULL); // list ends properly
    6.71 +    
    6.72 +    cout << "\nduplicating four-element stringlist…\n";
    6.73 +    stringlist_t* dst = stringlist_dup(src);
    6.74 +    assert(dst);
    6.75 +    
    6.76 +    stringlist_t* p_dst = dst;
    6.77 +    p = src;
    6.78 +
    6.79 +    cout << "checking contents\n";    
    6.80 +    while (p_dst) {
    6.81 +        assert(p_dst->value);
    6.82 +        assert(strcmp(p->value, p_dst->value) == 0);
    6.83 +        assert(p->value != p_dst->value); // ensure this is a copy
    6.84 +        cout << p_dst->value;
    6.85 +        p = p->next;
    6.86 +        p_dst = p_dst->next;
    6.87 +        assert((p == NULL) == (p_dst == NULL));
    6.88 +    }
    6.89 +    assert(p_dst == NULL);
    6.90 +        
    6.91 +    cout << "freeing stringlists…\n\n";
    6.92 +    free_stringlist(src);
    6.93 +    free_stringlist(dst);
    6.94 +    src = NULL;
    6.95 +    dst = NULL;
    6.96 +
    6.97 +    cout << "duplicating one-element stringlist…\n";    
    6.98 +    src = new_stringlist(str0);
    6.99 +    assert(src);
   6.100 +    dst = stringlist_dup(src);
   6.101 +    assert(strcmp(dst->value, str0) == 0);
   6.102 +    cout << "Value: " << src->value;
   6.103 +    assert(dst->next == NULL);
   6.104 +    cout << "one-element stringlist duped, next element is NULL\n";
   6.105 +    
   6.106 +    cout << "\nAdd to empty stringlist (node exists, but no value…)\n";
   6.107 +    if (src->value)
   6.108 +        free(src->value);
   6.109 +    src->value = NULL;
   6.110 +    stringlist_add(src, str2);
   6.111 +    assert(src->value);
   6.112 +    assert(strcmp(src->value, str2) == 0);
   6.113 +    assert(src->value != str2); // ensure this is a copy
   6.114 +    cout << src->value;
   6.115 +
   6.116 +    cout << "\nfreeing stringlists…\n\n";
   6.117 +    free_stringlist(src);
   6.118 +    free_stringlist(dst);
   6.119 +    
   6.120 +    src = NULL;
   6.121 +    dst = NULL;
   6.122 +    
   6.123 +    cout << "done.\n";
   6.124 +}
     7.1 --- a/test/stringlist_test.cc	Thu May 03 16:37:35 2018 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,115 +0,0 @@
     7.4 -// This file is under GNU General Public License 3.0
     7.5 -// see LICENSE.txt
     7.6 -
     7.7 -#include <stdlib.h>
     7.8 -#include <string.h>
     7.9 -#include "platform.h"
    7.10 -#include <iostream>
    7.11 -#include <fstream>
    7.12 -#include <assert.h>
    7.13 -
    7.14 -#include "stringlist.h"
    7.15 -
    7.16 -using namespace std;
    7.17 -
    7.18 -int main() {
    7.19 -    cout << "\n*** data structures: stringlist_test ***\n\n";
    7.20 -
    7.21 -    const char* str0 = "I am your father, Luke\n";
    7.22 -    
    7.23 -    // new_stringlist test code
    7.24 -    cout << "creating one-element stringlist…\n";
    7.25 -    
    7.26 -    stringlist_t* src = new_stringlist(str0);
    7.27 -    assert(src);
    7.28 -    assert(strcmp(src->value,str0) == 0);
    7.29 -    cout << "Value: " << src->value;
    7.30 -    assert(src->next == NULL);
    7.31 -    cout << "one-element stringlist created, next element is NULL\n";
    7.32 -    
    7.33 -    cout << "freeing stringlist…\n\n";
    7.34 -    free_stringlist(src);
    7.35 -    src = NULL;
    7.36 -    
    7.37 -    // test stringlist_add with four-element list
    7.38 -    cout << "creating four-element stringlist…\n";
    7.39 -    const char* str1 = "String 1";
    7.40 -    const char* str2 = "\tString 2";
    7.41 -    const char* str3 = "\tString 3";
    7.42 -    const char* str4 = "\tString 4\n";
    7.43 -    const char* strarr[4] = {str1, str2, str3, str4};
    7.44 -    cout << "stringlist_add on empty list…\n";
    7.45 -    src = stringlist_add(src, str1); // src is NULL
    7.46 -    assert(src);
    7.47 -    assert(stringlist_add(src, str2)); // returns ptr to new elt
    7.48 -    assert(stringlist_add(src, str3));
    7.49 -    assert(stringlist_add(src, str4));
    7.50 -    
    7.51 -    cout << "checking contents\n";
    7.52 -    stringlist_t* p = src;
    7.53 -    int i = 0;
    7.54 -    while (p) {
    7.55 -        assert(p->value);
    7.56 -        assert(strcmp(p->value, strarr[i++]) == 0);
    7.57 -        assert(p->value != *(strarr + i)); // ensure this is a copy
    7.58 -        cout << p->value;
    7.59 -        p = p->next;
    7.60 -    }
    7.61 -    assert(p == NULL); // list ends properly
    7.62 -    
    7.63 -    cout << "\nduplicating four-element stringlist…\n";
    7.64 -    stringlist_t* dst = stringlist_dup(src);
    7.65 -    assert(dst);
    7.66 -    
    7.67 -    stringlist_t* p_dst = dst;
    7.68 -    p = src;
    7.69 -
    7.70 -    cout << "checking contents\n";    
    7.71 -    while (p_dst) {
    7.72 -        assert(p_dst->value);
    7.73 -        assert(strcmp(p->value, p_dst->value) == 0);
    7.74 -        assert(p->value != p_dst->value); // ensure this is a copy
    7.75 -        cout << p_dst->value;
    7.76 -        p = p->next;
    7.77 -        p_dst = p_dst->next;
    7.78 -        assert((p == NULL) == (p_dst == NULL));
    7.79 -    }
    7.80 -    assert(p_dst == NULL);
    7.81 -        
    7.82 -    cout << "freeing stringlists…\n\n";
    7.83 -    free_stringlist(src);
    7.84 -    free_stringlist(dst);
    7.85 -    src = NULL;
    7.86 -    dst = NULL;
    7.87 -
    7.88 -    cout << "duplicating one-element stringlist…\n";    
    7.89 -    src = new_stringlist(str0);
    7.90 -    assert(src);
    7.91 -    dst = stringlist_dup(src);
    7.92 -    assert(strcmp(dst->value, str0) == 0);
    7.93 -    cout << "Value: " << src->value;
    7.94 -    assert(dst->next == NULL);
    7.95 -    cout << "one-element stringlist duped, next element is NULL\n";
    7.96 -    
    7.97 -    cout << "\nAdd to empty stringlist (node exists, but no value…)\n";
    7.98 -    if (src->value)
    7.99 -        free(src->value);
   7.100 -    src->value = NULL;
   7.101 -    stringlist_add(src, str2);
   7.102 -    assert(src->value);
   7.103 -    assert(strcmp(src->value, str2) == 0);
   7.104 -    assert(src->value != str2); // ensure this is a copy
   7.105 -    cout << src->value;
   7.106 -
   7.107 -    cout << "\nfreeing stringlists…\n\n";
   7.108 -    free_stringlist(src);
   7.109 -    free_stringlist(dst);
   7.110 -    
   7.111 -    src = NULL;
   7.112 -    dst = NULL;
   7.113 -    
   7.114 -    cout << "done.\n";
   7.115 -
   7.116 -    return 0;
   7.117 -}
   7.118 -