Added the testCase and memory profiler
[SXSI/TextCollection.git] / testTextCollection.cpp
index d89a328..dd37ff1 100644 (file)
@@ -1,5 +1,7 @@
 // Test driver for text collection
 #include <iostream>
+#include <cstdlib>
+#include "HeapProfiler.h"
 using std::cout;
 using std::endl;
 
@@ -28,47 +30,23 @@ void printFullResult(TextCollection::full_result fr)
 
 int main()
 {
-    uchar *text = (uchar*) "acabab";
-    TextCollection *csa = TextCollection::InitTextCollection(1);
-    csa->InsertText(text);
-    text = (uchar*) "abaca";
-    csa->InsertText(text);
-    text = (uchar*) "abacb";
-    csa->InsertText(text);
-
-    csa->MakeStatic();
-//    FILE *pFile = fopen ( "mysave.txt" , "rb" );
-//    csa->Load(pFile);
-    
-    text = csa->GetText(0);
-    cout << "Text 0: \"" << text << "\"" << endl;
-    delete [] text;
-    text = csa->GetText(1);
-    cout << "Text 1: \"" << text << "\"" << endl;
-    delete [] text;
-    text = csa->GetText(2);
-    cout << "Text 2: \"" << text << "\"" << endl;
-    delete [] text;
-    
-    text = csa->GetText(2, 2, 4);
-    cout << "Substring of Text 3: \"" << text << "\"" << endl;
-    delete [] text;
-    
-    printf("n:o contains: %u\n", csa->CountContains((uchar *)"ac"));
-    printf("n:o suffix: %u\n", csa->CountSuffix((uchar *)"b"));
-    printf("n:o equal: %u\n", csa->CountEqual((uchar *)"acabab"));
-    printf("is equal: %u\n", csa->IsEqual((uchar *)"abacb"));
-    
-    TextCollection::document_result dr;
-    dr = csa->Contains((uchar*)"ab");
-    printDocumentResult(dr);
-
-    TextCollection::full_result fr;
-    fr = csa->FullContains((uchar *)"ab");
-    printFullResult(fr);
-
-//    FILE *pFile2 = fopen ( "mysave.txt" , "wb" );
-//    csa->Save(pFile2);
-
-    delete csa;
+  std::string kbd;
+  uchar * str = (uchar*) "";
+
+  TextCollection *csa = TextCollection::InitTextCollection(64);
+  for(int i = 0; i<1000000; i++){
+    csa->InsertText(str);    
+  };
+  std::cerr << "Before MakeStatic() [press enter]\n";
+  std::cin >> kbd;
+  std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
+  csa->MakeStatic();
+  std::cerr << "After MakeStatic() [press enter]\n";
+  std::cin >> kbd;
+  std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
+  delete csa;
+  std::cerr << "After Delete [press enter]\n";
+  std::cerr << "heap usage: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
+  std::cin >> kbd;
+  return 0;
 }