SIS
Symmetric Index Structures
/Users/dbr/ma/src/t/VoidSequenceAdapterTest.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <cstring>
00003 #include <string>
00004 
00005 #include "../lmu/cis/sis/adapter/VoidSequenceAdapter.hpp"
00006 
00007 using lmu::cis::sis::VoidSequenceAdapter;
00008 using lmu::cis::sis::VoidSequenceAdapterDollarized;
00009 
00010 void TEST_FAILED(char* msg) {
00011     std::cerr << msg << std::endl;
00012     exit(EXIT_FAILURE);
00013 }
00014 
00015 int main() {
00016     
00017     const char* c_teststring = {"voidseq"};
00018     std::string cpp_teststring(c_teststring);
00019     
00020     std::cout << "Test 1" << std::endl;
00021     try {
00022         VoidSequenceAdapter v1(c_teststring);
00023         VoidSequenceAdapter v2(cpp_teststring);
00024 
00025         char msg[10000];
00026         int res = memcmp(v1.get(), v2.get(), strlen(c_teststring-1));
00027         sprintf(msg, "char * test failed -- result of v1.get() not equal to input string, first character that's different: %d", res);
00028 
00029         if ( res != 0 ) {
00030             TEST_FAILED(msg);
00031         } else {
00032             std::cerr << "Test 1 successful" << std::endl;
00033         }
00034     } catch (...) {
00035         // MESSAGE();
00036         std::cerr << "Some test failed" << std::endl;
00037         exit(EXIT_FAILURE);
00038     }
00039 
00040     std::cout << "Test 2" << std::endl;
00041     try {
00042         VoidSequenceAdapter v1(c_teststring);
00043         VoidSequenceAdapter v2;
00044         v2.Add(cpp_teststring);
00045 
00046         char msg[10000];
00047         int res = memcmp(v1.get(), v2.get(), strlen(c_teststring-1));
00048         sprintf(msg, "char * test failed -- result of v1.get() not equal to input string, first character that's different: %d", res);
00049 
00050         if ( res != 0 ) {
00051             TEST_FAILED(msg);
00052         } else {
00053             std::cerr << "Test 2 successful" << std::endl;
00054         }
00055     } catch (...) {
00056         // MESSAGE();
00057         std::cerr << "Some test failed" << std::endl;
00058         exit(EXIT_FAILURE);
00059     }
00060 
00061     std::cout << "Test 3" << std::endl;
00062     try {
00063         VoidSequenceAdapter v1(c_teststring);
00064         VoidSequenceAdapter v2;
00065         v2.Add(v1.get());
00066 
00067         char msg[10000];
00068         int res = memcmp(v1.get(), v2.get(), strlen(c_teststring-1));
00069         sprintf(msg, "char * test failed -- result of v1.get() not equal to input string, first character that's different: %d", res);
00070 
00071         if ( res != 0 ) {
00072             TEST_FAILED(msg);
00073         } else {
00074             std::cerr << "Test 3 successful" << std::endl;
00075         }
00076     } catch (...) {
00077         // MESSAGE();
00078         std::cerr << "Some test failed" << std::endl;
00079         exit(EXIT_FAILURE);
00080     }
00081 
00082 
00083     std::cout << "Test 4" << std::endl;
00084     try {
00085         VoidSequenceAdapterDollarized v1(c_teststring);
00086         VoidSequenceAdapter v2(c_teststring);
00087         v2.dollarizer();
00088 
00089         char msg[10000];
00090         int res = memcmp(v1.get(), v2.get(), strlen(c_teststring-1));
00091         sprintf(msg, "char * test failed -- result of v1.get() not equal to input string, first character that's different: %d", res);
00092 
00093         if ( res != 0 ) {
00094             TEST_FAILED(msg);
00095         } else {
00096             std::cerr << "Test 4 successful" << std::endl;
00097         }
00098     } catch (...) {
00099         // MESSAGE();
00100         std::cerr << "Some test failed" << std::endl;
00101         exit(EXIT_FAILURE);
00102     }
00103 
00104     std::cout << "Test 5" << std::endl;
00105     try {
00106         VoidSequenceAdapter v1(c_teststring);
00107         
00108         char msg[10000];
00109 
00110         int res = v1.length(); //, strlen(c_teststring-1), 1);
00111 
00112         if ( v1.length() != 7 ) {
00113             sprintf(msg, "char * test failed -- %s!", "length is not correct");
00114             TEST_FAILED(msg);
00115         } else {
00116             std::cerr << "Test 5 successful" << std::endl;
00117         }
00118     } catch (...) {
00119         // MESSAGE();
00120         std::cerr << "Some test failed" << std::endl;
00121         exit(EXIT_FAILURE);
00122     }
00123     // std::cout << "Test 5" << std::endl;
00124     // try {
00125     //     VoidSequenceAdapter v1(c_teststring);
00126     // 
00127     //     char msg[10000];
00128     //     int res = memcmp(v1.at(1), (void*)'v', 1);
00129     //     sprintf(msg, "char * test failed -- result of v1.get() not equal to input string, first character that's different: %d", res);
00130     // 
00131     //     if ( res != 0 ) {
00132     //         TEST_FAILED(msg);
00133     //     } else {
00134     //         std::cerr << "Test 5 successful" << std::endl;
00135     //     }
00136     // } catch (...) {
00137     //     // MESSAGE();
00138     //     std::cerr << "Some test failed" << std::endl;
00139     //     exit(EXIT_FAILURE);
00140     // }
00141 
00142     return EXIT_SUCCESS;
00143 }