home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / tests / DB / AddressDatabaseTest.cc next >
C/C++ Source or Header  |  2000-06-10  |  4KB  |  133 lines

  1. //
  2. //  $Id: AddressDatabaseTest.cc,v 1.3 2000/06/10 00:20:05 sergey Exp $
  3. //
  4.  
  5. #include <Pilot.h>
  6. #include <stdio.h>
  7. #include "../Test.h"
  8. #include "DB/Database.h"
  9. #include "DB/AddressAppInfo.h"
  10. #include "DB/AdresseRecord.h"
  11.  
  12. namespace DB
  13. {
  14.     class AddressDatabaseTest: public Test
  15.     {
  16.     public:
  17.         virtual const char* name() const { return "AddressDatabaseTest"; }
  18.  
  19.         virtual void runTest()
  20.         {
  21.             testAppInfo();
  22.  
  23.             testNullRecord();
  24.             testRecord();
  25.         }
  26.  
  27.         void testAppInfo()
  28.         {
  29.             Database db;
  30.             testAssert(db.open(0, "AddressDB", dmModeReadOnly));
  31.  
  32.             AddressAppInfo appInfo;
  33.             testAssert(db.readAppInfo(appInfo));
  34.  
  35.             const char* labels[] = { "Work", "Home", "Fax", "Other", "E-mail", "Main", "Pager", "Mobile" };
  36.  
  37.             for (int i = 0; i < AddressAppInfo::PHONE_LABEL_COUNT; ++i)
  38.                 testAssert(StrCompare(appInfo.phoneLabel(i), labels[i]) == 0);
  39.         }
  40.  
  41.         void testNullRecord()
  42.         {
  43.             AdresseRecord rec1;
  44.             testAssert(rec1.index() == -1);
  45.  
  46.             AdresseRecord rec2;
  47.             rec2 = rec1;
  48.             testAssert(rec2.index() == -1);
  49.  
  50.             AdresseRecord rec3(rec2);
  51.             testAssert(rec3.index() == -1);
  52.  
  53.             testAdresseEntries(rec3);
  54.         }
  55.  
  56.         void testRecord()
  57.         {
  58.             Database db;
  59.             testAssert(db.open(0, "AddressDB", dmModeReadOnly));
  60.             if (db.recordCount() == 0)
  61.             {
  62.                 testAssertComment(false, "AddressDB is empty!");
  63.                 return;
  64.             }
  65.  
  66.             //***
  67.  
  68.             AdresseRecord rec1;
  69.  
  70.             testAssert(db.readRecord(0, rec1));
  71.             testAssert(rec1.entry("lastName") != 0);
  72.  
  73.             //***
  74.  
  75.             AdresseRecord rec2 = rec1;
  76.             testAssert(StrCompare(rec2.entry("lastName"), rec1.entry("lastName")) == 0);
  77.  
  78.             //***
  79.  
  80.             rec1 = AdresseRecord();
  81.             testAssert(rec1.entry("lastName") == 0);
  82.  
  83.             //***
  84.  
  85.             testAssert(db.readRecord(0, rec1));
  86.             testAssert(rec1.entry("lastName") != 0);
  87.  
  88.             //***
  89.  
  90.             testAdresseEntries(rec1);
  91.             testPhoneLabels(rec1);
  92.         }
  93.  
  94.         void testAdresseEntries(const AdresseRecord& record)
  95.         {
  96.             testAssert(record.isEntry("lastName"));
  97.             testAssert(record.isEntry("firstName"));
  98.             testAssert(record.isEntry("company"));
  99.             testAssert(record.isEntry("phone1"));
  100.             testAssert(record.isEntry("phone2"));
  101.             testAssert(record.isEntry("phone3"));
  102.             testAssert(record.isEntry("phone4"));
  103.             testAssert(record.isEntry("phone5"));
  104.             testAssert(record.isEntry("address"));
  105.             testAssert(record.isEntry("city"));
  106.             testAssert(record.isEntry("state"));
  107.             testAssert(record.isEntry("zip"));
  108.             testAssert(record.isEntry("country"));
  109.             testAssert(record.isEntry("title"));
  110.             testAssert(record.isEntry("custom1"));
  111.             testAssert(record.isEntry("custom2"));
  112.             testAssert(record.isEntry("custom3"));
  113.             testAssert(record.isEntry("custom4"));
  114.             testAssert(record.isEntry("note"));
  115.         }
  116.  
  117.         void testPhoneLabels(const AdresseRecord& record)
  118.         {
  119.             testAssert(record.phoneEntryLabel(0) == 0);
  120.             testAssert(record.phoneEntryLabel(1) == 1);
  121.             testAssert(record.phoneEntryLabel(2) == 2);
  122.             testAssert(record.phoneEntryLabel(3) == 3);
  123.             testAssert(record.phoneEntryLabel(4) == 4);
  124.         }
  125.     };
  126. }
  127.  
  128. Test& GetAddressDatabaseTest()
  129. {
  130.     static DB::AddressDatabaseTest test;
  131.     return test;
  132. }
  133.