home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 Mobile
/
Chip_Mobile_2001.iso
/
palm
/
business
/
printcar
/
printcar.exe
/
tests
/
DB
/
AddressDatabaseTest.cc
next >
Wrap
C/C++ Source or Header
|
2000-06-10
|
4KB
|
133 lines
//
// $Id: AddressDatabaseTest.cc,v 1.3 2000/06/10 00:20:05 sergey Exp $
//
#include <Pilot.h>
#include <stdio.h>
#include "../Test.h"
#include "DB/Database.h"
#include "DB/AddressAppInfo.h"
#include "DB/AdresseRecord.h"
namespace DB
{
class AddressDatabaseTest: public Test
{
public:
virtual const char* name() const { return "AddressDatabaseTest"; }
virtual void runTest()
{
testAppInfo();
testNullRecord();
testRecord();
}
void testAppInfo()
{
Database db;
testAssert(db.open(0, "AddressDB", dmModeReadOnly));
AddressAppInfo appInfo;
testAssert(db.readAppInfo(appInfo));
const char* labels[] = { "Work", "Home", "Fax", "Other", "E-mail", "Main", "Pager", "Mobile" };
for (int i = 0; i < AddressAppInfo::PHONE_LABEL_COUNT; ++i)
testAssert(StrCompare(appInfo.phoneLabel(i), labels[i]) == 0);
}
void testNullRecord()
{
AdresseRecord rec1;
testAssert(rec1.index() == -1);
AdresseRecord rec2;
rec2 = rec1;
testAssert(rec2.index() == -1);
AdresseRecord rec3(rec2);
testAssert(rec3.index() == -1);
testAdresseEntries(rec3);
}
void testRecord()
{
Database db;
testAssert(db.open(0, "AddressDB", dmModeReadOnly));
if (db.recordCount() == 0)
{
testAssertComment(false, "AddressDB is empty!");
return;
}
//***
AdresseRecord rec1;
testAssert(db.readRecord(0, rec1));
testAssert(rec1.entry("lastName") != 0);
//***
AdresseRecord rec2 = rec1;
testAssert(StrCompare(rec2.entry("lastName"), rec1.entry("lastName")) == 0);
//***
rec1 = AdresseRecord();
testAssert(rec1.entry("lastName") == 0);
//***
testAssert(db.readRecord(0, rec1));
testAssert(rec1.entry("lastName") != 0);
//***
testAdresseEntries(rec1);
testPhoneLabels(rec1);
}
void testAdresseEntries(const AdresseRecord& record)
{
testAssert(record.isEntry("lastName"));
testAssert(record.isEntry("firstName"));
testAssert(record.isEntry("company"));
testAssert(record.isEntry("phone1"));
testAssert(record.isEntry("phone2"));
testAssert(record.isEntry("phone3"));
testAssert(record.isEntry("phone4"));
testAssert(record.isEntry("phone5"));
testAssert(record.isEntry("address"));
testAssert(record.isEntry("city"));
testAssert(record.isEntry("state"));
testAssert(record.isEntry("zip"));
testAssert(record.isEntry("country"));
testAssert(record.isEntry("title"));
testAssert(record.isEntry("custom1"));
testAssert(record.isEntry("custom2"));
testAssert(record.isEntry("custom3"));
testAssert(record.isEntry("custom4"));
testAssert(record.isEntry("note"));
}
void testPhoneLabels(const AdresseRecord& record)
{
testAssert(record.phoneEntryLabel(0) == 0);
testAssert(record.phoneEntryLabel(1) == 1);
testAssert(record.phoneEntryLabel(2) == 2);
testAssert(record.phoneEntryLabel(3) == 3);
testAssert(record.phoneEntryLabel(4) == 4);
}
};
}
Test& GetAddressDatabaseTest()
{
static DB::AddressDatabaseTest test;
return test;
}