home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / samples / ooftst11.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-27  |  2.3 KB  |  98 lines  |  [TEXT/CWIE]

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST11
  4.  
  5. // this sample uses shows an easy way to generate test data
  6. // it comes from a real project, which is why the CLASS_TABLE
  7. // looks a bit funny - it was generated by AppMaker
  8.  
  9. // Simple stream I/O is used to interact with the user.
  10. #include "oofile.hpp"
  11.  
  12.  
  13. CLASS_TABLE(CdbPhonePro)
  14.     dbChar        LastName;
  15.     dbChar        FirstName;
  16.     dbChar        Title;
  17.     dbChar        Extn;
  18.     dbChar        Department;
  19.     dbChar        Pager;
  20.  
  21. CdbPhonePro() : dbTable("PhonePro") ,
  22.     LastName(50, "LastName"),
  23.     FirstName(30, "FirstName"),
  24.     Title(50, "Title"),
  25.     Extn(24, "Extn"),
  26.     Department(50, "Department"),
  27.     Pager(24, "Pager")
  28. {
  29. LastName.index(kIndexCompress);
  30. FirstName.index(kIndexCompress);
  31. Title.index(kIndexCompress);
  32. Extn.index(kIndexCompress);
  33. Department.index(kIndexCompress);
  34. Pager.index(kIndexCompress);
  35.  
  36. };
  37. };
  38.  
  39.  
  40. dbConnect_ctree theDB;
  41. CdbPhonePro    PhonePro;
  42.  
  43. int main()
  44. {
  45.  
  46. #ifdef _Macintosh
  47. // change types of files created by c-tree (given modification to ctclib.c)
  48. ctMacCreator = 'PhPr';
  49. ctMacType = 'OOCT';
  50. #endif
  51.  
  52.     cout << "OOFILE Validation Suite - Test 11\n"
  53.          << "Simple test to demonstrate using the inbuilt test data generator" << endl
  54.          << "as you would to generate random data for a real project" << endl << endl;
  55.          
  56.     cout << "Enter the name of a text file from which random chunks will be drawn" << endl
  57.          << "File: " << flush;
  58.          
  59.     char testFileName[255];
  60.     cin.width(255);
  61.     cin  >> testFileName;
  62.     
  63.     if (!dbConnect::fileExists(testFileName)) {
  64.         cout << "Sorry, couldn't find the file: " << testFileName << endl;
  65.         return EXIT_SUCCESS;
  66.     }
  67.     
  68.     cout << endl << "Number of test records: " << flush;
  69.     unsigned long numRecs;
  70.     cin >> numRecs;
  71.  
  72.     if (numRecs==0)
  73.         return EXIT_SUCCESS;
  74.         
  75.     if (dbConnect::fileExists("ooftst11.db")) {
  76.         theDB.openConnection("ooftst11.db");
  77.         cout << "Deleting the " << PhonePro.countAll() << " records from the last run..." << endl;
  78.         PhonePro.deleteAll();
  79.     }
  80.     else {
  81.         theDB.newConnection("ooftst11.db");
  82.     }
  83.     
  84.     cout << endl << "Generating " << numRecs << " test records..." << endl;
  85.     
  86.     theDB.generateTestData(testFileName, numRecs);
  87.     
  88.     cout << endl << "Do you want to display the test data? (Y/N) " << flush;
  89.     char yn = 'N';
  90.     cin >> yn;
  91.     
  92.     if ((yn=='y') || (yn=='Y'))
  93.         cout << theDB << endl;
  94.     
  95.     cout << "done" << endl;
  96.  
  97.     return EXIT_SUCCESS;
  98. }