ICU-3662 Move data based test framework to test library

X-SVN-Rev: 14737
This commit is contained in:
George Rhoten 2004-03-23 23:18:43 +00:00
parent de96043899
commit f1414e0160
9 changed files with 40 additions and 961 deletions

View file

@ -482,6 +482,9 @@ Package=<4>
Begin Project Dependency
Project_Dep_Name toolutil
End Project Dependency
Begin Project Dependency
Project_Dep_Name ctestfw
End Project Dependency
}}}
###############################################################################

View file

@ -1,219 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Created by weiv 05/09/2002 */
#include "datamap.h"
#include "unicode/resbund.h"
#include <stdlib.h>
int32_t
DataMap::utoi(const UnicodeString &s) const
{
char ch[256];
const UChar *u = s.getBuffer();
int32_t len = s.length();
u_UCharsToChars(u, ch, len);
ch[len] = 0; /* include terminating \0 */
return atoi(ch);
}
U_CDECL_BEGIN
void U_CALLCONV
deleteResBund(void *obj) {
delete (ResourceBundle *)obj;
}
U_CDECL_END
RBDataMap::~RBDataMap()
{
delete fData;
}
RBDataMap::RBDataMap()
{
UErrorCode status = U_ZERO_ERROR;
fData = new Hashtable(TRUE, status);
fData->setValueDeleter(deleteResBund);
}
// init from table resource
// will put stuff in hashtable according to
// keys.
RBDataMap::RBDataMap(UResourceBundle *data, UErrorCode &status)
{
fData = new Hashtable(TRUE, status);
fData->setValueDeleter(deleteResBund);
init(data, status);
}
// init from headers and resource
// with checking the whether the size of resource matches
// header size
RBDataMap::RBDataMap(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status)
{
fData = new Hashtable(TRUE, status);
fData->setValueDeleter(deleteResBund);
init(headers, data, status);
}
void RBDataMap::init(UResourceBundle *data, UErrorCode &status) {
int32_t i = 0;
fData->removeAll();
UResourceBundle *t = NULL;
for(i = 0; i < ures_getSize(data); i++) {
t = ures_getByIndex(data, i, t, &status);
fData->put(UnicodeString(ures_getKey(t), ""), new ResourceBundle(t, status), status);
}
ures_close(t);
}
void RBDataMap::init(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status)
{
int32_t i = 0;
fData->removeAll();
UResourceBundle *t = NULL;
const UChar *key = NULL;
int32_t keyLen = 0;
if(ures_getSize(headers) == ures_getSize(data)) {
for(i = 0; i < ures_getSize(data); i++) {
t = ures_getByIndex(data, i, t, &status);
key = ures_getStringByIndex(headers, i, &keyLen, &status);
fData->put(UnicodeString(key, keyLen), new ResourceBundle(t, status), status);
}
} else {
// error
status = U_INVALID_FORMAT_ERROR;
}
ures_close(t);
}
const ResourceBundle *RBDataMap::getItem(const char* key, UErrorCode &status) const
{
if(U_FAILURE(status)) {
return NULL;
}
UnicodeString hashKey(key, "");
const ResourceBundle *r = (ResourceBundle *)fData->get(hashKey);
if(r != NULL) {
return r;
} else {
status = U_MISSING_RESOURCE_ERROR;
return NULL;
}
}
const UnicodeString RBDataMap::getString(const char* key, UErrorCode &status) const
{
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
return r->getString(status);
} else {
status = U_MISSING_RESOURCE_ERROR;
return UnicodeString();
}
}
int32_t
RBDataMap::getInt28(const char* key, UErrorCode &status) const
{
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
return r->getInt(status);
} else {
return 0;
}
}
uint32_t
RBDataMap::getUInt28(const char* key, UErrorCode &status) const
{
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
return r->getUInt(status);
} else {
return 0;
}
}
const int32_t *
RBDataMap::getIntVector(int32_t &length, const char *key, UErrorCode &status) const {
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
return r->getIntVector(length, status);
} else {
return NULL;
}
}
const uint8_t *
RBDataMap::getBinary(int32_t &length, const char *key, UErrorCode &status) const {
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
return r->getBinary(length, status);
} else {
return NULL;
}
}
int32_t RBDataMap::getInt(const char* key, UErrorCode &status) const
{
UnicodeString r = this->getString(key, status);
if(U_SUCCESS(status)) {
return utoi(r);
} else {
return 0;
}
}
const UnicodeString* RBDataMap::getStringArray(int32_t& count, const char* key, UErrorCode &status) const
{
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
int32_t i = 0;
count = r->getSize();
if(count <= 0) {
return NULL;
}
UnicodeString *result = new UnicodeString[count];
for(i = 0; i<count; i++) {
result[i] = r->getStringEx(i, status);
}
return result;
} else {
status = U_MISSING_RESOURCE_ERROR;
return NULL;
}
}
const int32_t* RBDataMap::getIntArray(int32_t& count, const char* key, UErrorCode &status) const
{
const ResourceBundle *r = getItem(key, status);
if(U_SUCCESS(status)) {
int32_t i = 0;
count = r->getSize();
if(count <= 0) {
return NULL;
}
int32_t *result = new int32_t[count];
UnicodeString stringRes;
for(i = 0; i<count; i++) {
stringRes = r->getStringEx(i, status);
result[i] = utoi(stringRes);
}
return result;
} else {
status = U_MISSING_RESOURCE_ERROR;
return NULL;
}
}

View file

@ -1,132 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Created by weiv 05/09/2002 */
#ifndef INTLTST_DATAMAP
#define INTLTST_DATAMAP
#include "hash.h"
#include "unicode/ures.h"
#include "unicode/resbund.h"
/** Holder of test data and settings. Allows addressing of items by name.
* For test cases, names are defined in the "Headers" section. For settings
* and info data, names are keys in data. Currently, we return scalar strings
* and integers and arrays of strings and integers. Arrays should be deposited
* of by the user.
*/
class DataMap {
public:
virtual ~DataMap() {};
protected:
DataMap() {};
int32_t utoi(const UnicodeString &s) const;
public:
/** get the string from the DataMap. Addressed by name
* @param key name of the data field.
* @return a string containing the data
*/
virtual const UnicodeString getString(const char* key, UErrorCode &status) const = 0;
/** get the string from the DataMap. Addressed by name
* parses a bundle string into an integer
* @param key name of the data field.
* @return an integer containing the data
*/
virtual int32_t getInt(const char* key, UErrorCode &status) const = 0;
/**
* Get a signed integer without runtime parsing.
* @param key name of the data field.
* @param status UErrorCode in/out parameter
* @return the integer
*/
virtual int32_t getInt28(const char* key, UErrorCode &status) const = 0;
/**
* Get an unsigned integer without runtime parsing.
* @param key name of the data field.
* @param status UErrorCode in/out parameter
* @return the integer
*/
virtual uint32_t getUInt28(const char* key, UErrorCode &status) const = 0;
/**
* Get a vector of integers without runtime parsing.
* @param length output parameter for the length of the vector
* @param key name of the data field.
* @param status UErrorCode in/out parameter
* @return the integer vector, do not delete
*/
virtual const int32_t *getIntVector(int32_t &length, const char *key, UErrorCode &status) const = 0;
/**
* Get binary data without runtime parsing.
* @param length output parameter for the length of the data
* @param key name of the data field.
* @param status UErrorCode in/out parameter
* @return the binary data, do not delete
*/
virtual const uint8_t *getBinary(int32_t &length, const char *key, UErrorCode &status) const = 0;
/** get an array of strings from the DataMap. Addressed by name.
* The user must dispose of it after usage, using delete.
* @param key name of the data field.
* @return a string array containing the data
*/
virtual const UnicodeString* getStringArray(int32_t& count, const char* key, UErrorCode &status) const = 0;
/** get an array of integers from the DataMap. Addressed by name.
* The user must dispose of it after usage, using delete.
* @param key name of the data field.
* @return an integer array containing the data
*/
virtual const int32_t* getIntArray(int32_t& count, const char* key, UErrorCode &status) const = 0;
// ... etc ...
};
// This one is already concrete - it is going to be instantiated from
// concrete data by TestData children...
class RBDataMap : public DataMap{
private:
Hashtable *fData;
public:
virtual ~RBDataMap();
public:
RBDataMap();
RBDataMap(UResourceBundle *data, UErrorCode &status);
RBDataMap(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status);
public:
void init(UResourceBundle *data, UErrorCode &status);
void init(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status);
virtual const ResourceBundle *getItem(const char* key, UErrorCode &status) const;
virtual const UnicodeString getString(const char* key, UErrorCode &status) const;
virtual int32_t getInt28(const char* key, UErrorCode &status) const;
virtual uint32_t getUInt28(const char* key, UErrorCode &status) const;
virtual const int32_t *getIntVector(int32_t &length, const char *key, UErrorCode &status) const;
virtual const uint8_t *getBinary(int32_t &length, const char *key, UErrorCode &status) const;
virtual int32_t getInt(const char* key, UErrorCode &status) const;
virtual const UnicodeString* getStringArray(int32_t& count, const char* key, UErrorCode &status) const;
virtual const int32_t* getIntArray(int32_t& count, const char* key, UErrorCode &status) const;
// ... etc ...
};
#endif

View file

@ -45,7 +45,7 @@ RSC=rc.exe
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
# ADD CPP /nologo /G6 /MT /Za /W3 /GX /Zi /Ox /Ob0 /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
# ADD CPP /nologo /G6 /MT /Za /W3 /GX /Zi /Ox /Ob0 /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /I "..\..\tools\ctestfw" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@ -71,7 +71,7 @@ LINK32=link.exe
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
# ADD CPP /nologo /G6 /MTd /Za /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "UDATA_MAP_DLL" /FR /FD /GZ /c
# ADD CPP /nologo /G6 /MTd /Za /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /I "..\..\tools\ctestfw" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "UDATA_MAP_DLL" /FR /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@ -97,7 +97,7 @@ LINK32=link.exe
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
# ADD CPP /nologo /MD /Za /W3 /GX /Zi /O2 /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD CPP /nologo /MD /Za /W3 /GX /Zi /O2 /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /I "..\..\tools\ctestfw" /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@ -122,7 +122,7 @@ LINK32=link.exe
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN64" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
# ADD CPP /nologo /MDd /Za /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /D "WIN64" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "UDATA_MAP_DLL" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FR /FD /GZ /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD CPP /nologo /MDd /Za /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /I "..\..\..\source\common" /I "..\..\..\source\i18n" /I "..\..\tools\toolutil" /I "..\..\tools\ctestfw" /D "WIN64" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "UDATA_MAP_DLL" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FR /FD /GZ /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@ -776,14 +776,6 @@ SOURCE=.\testidna.h
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\datamap.cpp
# End Source File
# Begin Source File
SOURCE=.\datamap.h
# End Source File
# Begin Source File
SOURCE=.\intltest.cpp
# End Source File
# Begin Source File
@ -808,28 +800,12 @@ SOURCE=.\itutil.h
# End Source File
# Begin Source File
SOURCE=.\testdata.cpp
# End Source File
# Begin Source File
SOURCE=.\testdata.h
# End Source File
# Begin Source File
SOURCE=.\testutil.cpp
# End Source File
# Begin Source File
SOURCE=.\testutil.h
# End Source File
# Begin Source File
SOURCE=.\tstdtmod.cpp
# End Source File
# Begin Source File
SOURCE=.\tstdtmod.h
# End Source File
# End Group
# Begin Group "normalization"

View file

@ -1,140 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Created by weiv 05/09/2002 */
#include "testdata.h"
TestData::TestData(const char* name)
: name(name),
fInfo(NULL),
fCurrSettings(NULL),
fCurrCase(NULL),
fSettingsSize(0),
fCasesSize(0),
fCurrentSettings(0),
fCurrentCase(0)
{
}
TestData::~TestData() {
if(fInfo != NULL) {
delete fInfo;
}
if(fCurrSettings != NULL) {
delete fCurrSettings;
}
if(fCurrCase != NULL) {
delete fCurrCase;
}
}
const char * TestData::getName() const
{
return name;
}
RBTestData::RBTestData(const char* name)
: TestData(name),
fData(NULL),
fHeaders(NULL),
fSettings(NULL),
fCases(NULL)
{
}
RBTestData::RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status)
: TestData(ures_getKey(data)),
fData(data),
fHeaders(headers),
fSettings(NULL),
fCases(NULL)
{
UErrorCode intStatus = U_ZERO_ERROR;
UResourceBundle *currHeaders = ures_getByKey(data, "Headers", NULL, &intStatus);
if(intStatus == U_ZERO_ERROR) {
ures_close(fHeaders);
fHeaders = currHeaders;
} else {
intStatus = U_ZERO_ERROR;
}
fSettings = ures_getByKey(data, "Settings", NULL, &intStatus);
fSettingsSize = ures_getSize(fSettings);
UResourceBundle *info = ures_getByKey(data, "Info", NULL, &intStatus);
if(U_SUCCESS(intStatus)) {
fInfo = new RBDataMap(info, status);
} else {
intStatus = U_ZERO_ERROR;
}
fCases = ures_getByKey(data, "Cases", NULL, &status);
fCasesSize = ures_getSize(fCases);
ures_close(info);
}
RBTestData::~RBTestData()
{
ures_close(fData);
ures_close(fHeaders);
ures_close(fSettings);
ures_close(fCases);
}
UBool RBTestData::getInfo(const DataMap *& info, UErrorCode &/*status*/) const
{
if(fInfo) {
info = fInfo;
return TRUE;
} else {
info = NULL;
return FALSE;
}
}
UBool RBTestData::nextSettings(const DataMap *& settings, UErrorCode &status)
{
UErrorCode intStatus = U_ZERO_ERROR;
UResourceBundle *data = ures_getByIndex(fSettings, fCurrentSettings++, NULL, &intStatus);
if(U_SUCCESS(intStatus)) {
// reset the cases iterator
fCurrentCase = 0;
if(fCurrSettings == NULL) {
fCurrSettings = new RBDataMap(data, status);
} else {
((RBDataMap *)fCurrSettings)->init(data, status);
}
ures_close(data);
settings = fCurrSettings;
return TRUE;
} else {
settings = NULL;
return FALSE;
}
}
UBool RBTestData::nextCase(const DataMap *& nextCase, UErrorCode &status)
{
UErrorCode intStatus = U_ZERO_ERROR;
UResourceBundle *currCase = ures_getByIndex(fCases, fCurrentCase++, NULL, &intStatus);
if(U_SUCCESS(intStatus)) {
if(fCurrCase == NULL) {
fCurrCase = new RBDataMap(fHeaders, currCase, status);
} else {
((RBDataMap *)fCurrCase)->init(fHeaders, currCase, status);
}
ures_close(currCase);
nextCase = fCurrCase;
return TRUE;
} else {
nextCase = NULL;
return FALSE;
}
}

View file

@ -1,109 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Created by weiv 05/09/2002 */
/* Base class for data driven tests */
#ifndef INTLTST_TESTDATA
#define INTLTST_TESTDATA
#include "tstdtmod.h"
#include "datamap.h"
/** This is the class that abstracts one of the tests in a data file
* It is usually instantiated using TestDataModule::CreateTestData method
* This class provides two important methods: nextSettings and nextCase
* Usually, one walks through all settings and executes all cases for
* each setting. Each call to nextSettings resets the cases iterator.
* Individual test cases have to have the same number of fields as the
* number of entries in headers. Default headers can be specified in
* the TestDataModule info section. The default headers will be overriden
* by per-test headers.
* Example:
* DataMap *settings = NULL;
* DataMap *cases = NULL;
* while(nextSettings(settings, status)) {
* // set settings for the subtest
* while(nextCase(cases, status) {
* // process testcase
* }
* }
*/
class TestData {
const char* name;
protected:
DataMap *fInfo;
DataMap *fCurrSettings;
DataMap *fCurrCase;
int32_t fSettingsSize;
int32_t fCasesSize;
int32_t fCurrentSettings;
int32_t fCurrentCase;
/** constructor - don't use */
TestData(const char* name);
public:
virtual ~TestData();
const char* getName() const;
/** Get a pointer to an object owned DataMap that contains more information on this
* TestData object.
* Usual fields is "Description".
* @param info pass in a const DataMap pointer. If no info, it will be set to NULL
*/
virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0;
/** Gets the next set of settings for the test. Resets the cases iterator.
* DataMap is owned by the object and should not be deleted.
* @param settings a DataMap pointer provided by the user. Will be NULL if
* no more settings are available.
* @param status for reporting unexpected errors.
* @return A boolean, TRUE if there are settings, FALSE if there is no more
* settings.
*/
virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status) = 0;
/** Gets the next test case.
* DataMap is owned by the object and should not be deleted.
* @param data a DataMap pointer provided by the user. Will be NULL if
* no more cases are available.
* @param status for reporting unexpected errors.
* @return A boolean, TRUE if there are cases, FALSE if there is no more
* cases.
*/
virtual UBool nextCase(const DataMap *& data, UErrorCode &status) = 0;
};
// implementation of TestData that uses resource bundles
class RBTestData : public TestData {
UResourceBundle *fData;
UResourceBundle *fHeaders;
UResourceBundle *fSettings;
UResourceBundle *fCases;
public:
RBTestData(const char* name);
RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status);
private:
// RBTestData() {};
// RBTestData(const RBTestData& original) {};
RBTestData& operator=(const RBTestData& /*original*/) {return *this;};
public:
virtual ~RBTestData();
virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const;
virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status);
virtual UBool nextCase(const DataMap *& nextCase, UErrorCode &status);
};
#endif

View file

@ -1,169 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Created by weiv 05/09/2002 */
#include "tstdtmod.h"
#include "cmemory.h"
TestDataModule *TestDataModule::getTestDataModule(const char* name, TestLog& log, UErrorCode &status)
{
if(U_FAILURE(status)) {
return NULL;
}
TestDataModule *result = NULL;
// TODO: probe for resource bundle and then for XML.
// According to that, construct an appropriate driver object
result = new RBTestDataModule(name, log, status);
if(U_SUCCESS(status)) {
return result;
} else {
delete result;
return NULL;
}
}
TestDataModule::TestDataModule(const char* name, TestLog& log, UErrorCode& /*status*/)
: testName(name),
fInfo(NULL),
fLog(log)
{
}
TestDataModule::~TestDataModule() {
if(fInfo != NULL) {
delete fInfo;
}
}
const char * TestDataModule::getName() const
{
return testName;
}
RBTestDataModule::~RBTestDataModule()
{
ures_close(fTestData);
ures_close(fModuleBundle);
ures_close(fInfoRB);
uprv_free(tdpath);
}
RBTestDataModule::RBTestDataModule(const char* name, TestLog& log, UErrorCode& status)
: TestDataModule(name, log, status),
fModuleBundle(NULL),
fTestData(NULL),
fInfoRB(NULL),
tdpath(NULL)
{
fNumberOfTests = 0;
fDataTestValid = TRUE;
fModuleBundle = getTestBundle(name, status);
if(fDataTestValid) {
fTestData = ures_getByKey(fModuleBundle, "TestData", NULL, &status);
fNumberOfTests = ures_getSize(fTestData);
fInfoRB = ures_getByKey(fModuleBundle, "Info", NULL, &status);
if(status != U_ZERO_ERROR) {
log.errln("Unable to initalize test data - missing mandatory description resources!");
fDataTestValid = FALSE;
} else {
fInfo = new RBDataMap(fInfoRB, status);
}
}
}
UBool RBTestDataModule::getInfo(const DataMap *& info, UErrorCode &/*status*/) const
{
info = fInfo;
if(fInfo) {
return TRUE;
} else {
return FALSE;
}
}
TestData* RBTestDataModule::createTestData(int32_t index, UErrorCode &status) const
{
TestData *result = NULL;
UErrorCode intStatus = U_ZERO_ERROR;
if(fDataTestValid == TRUE) {
// Both of these resources get adopted by a TestData object.
UResourceBundle *DataFillIn = ures_getByIndex(fTestData, index, NULL, &status);
UResourceBundle *headers = ures_getByKey(fInfoRB, "Headers", NULL, &intStatus);
if(U_SUCCESS(status)) {
result = new RBTestData(DataFillIn, headers, status);
if(U_SUCCESS(status)) {
return result;
} else {
delete result;
}
} else {
ures_close(DataFillIn);
ures_close(headers);
}
} else {
status = U_MISSING_RESOURCE_ERROR;
}
return NULL;
}
TestData* RBTestDataModule::createTestData(const char* name, UErrorCode &status) const
{
TestData *result = NULL;
UErrorCode intStatus = U_ZERO_ERROR;
if(fDataTestValid == TRUE) {
// Both of these resources get adopted by a TestData object.
UResourceBundle *DataFillIn = ures_getByKey(fTestData, name, NULL, &status);
UResourceBundle *headers = ures_getByKey(fInfoRB, "Headers", NULL, &intStatus);
if(U_SUCCESS(status)) {
result = new RBTestData(DataFillIn, headers, status);
if(U_SUCCESS(status)) {
return result;
} else {
delete result;
}
} else {
ures_close(DataFillIn);
ures_close(headers);
}
} else {
status = U_MISSING_RESOURCE_ERROR;
}
return NULL;
}
//Get test data from ResourceBundles
UResourceBundle*
RBTestDataModule::getTestBundle(const char* bundleName, UErrorCode &status)
{
if(U_SUCCESS(status)) {
UResourceBundle *testBundle = NULL;
//const char* icu_data = (char*)loadTestData(status);
const char* icu_data = IntlTest::loadTestData(status);
if (testBundle == NULL) {
testBundle = ures_openDirect(icu_data, bundleName, &status);
if (status != U_ZERO_ERROR) {
fLog.errln(UnicodeString("Failed: could not load test data from resourcebundle: ") + UnicodeString(bundleName));
fDataTestValid = FALSE;
}
}
return testBundle;
} else {
return NULL;
}
}

View file

@ -1,120 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Created by weiv 05/09/2002 */
/* Base class for data driven tests */
#ifndef INTLTST_TESTMODULE
#define INTLTST_TESTMODULE
#include "unicode/utypes.h"
#include "unicode/unistr.h"
#include "intltest.h"
#include "unicode/ures.h"
#include "testdata.h"
#include "datamap.h"
/* This class abstracts the actual organization of the
* data for data driven tests
*/
class DataMap;
class TestData;
/** Facilitates internal logging of data driven test service
* It would be interesting to develop this into a full
* fledged control system as in Java.
*/
class TestLog : public IntlTest{
};
/** Main data driven test class. Corresponds to one named data
* unit (such as a resource bundle. It is instantiated using
* a factory method getTestDataModule
*/
class TestDataModule {
const char* testName;
protected:
DataMap *fInfo;
TestLog& fLog;
public:
/** Factory method.
* @param name name of the test module. Usually name of a resource bundle or a XML file
* @param log a logging class, used for internal error reporting.
* @param status if something goes wrong, status will be set
* @return a TestDataModule object. Use it to get test data from it
*/
static TestDataModule *getTestDataModule(const char* name, TestLog& log, UErrorCode &status);
virtual ~TestDataModule();
protected:
TestDataModule(const char* name, TestLog& log, UErrorCode& status);
public:
/** Name of this TestData module.
* @return a name
*/
const char * getName() const;
/** Get a pointer to an object owned DataMap that contains more information on this module
* Usual fields are "Description", "LongDescription", "Settings". Also, if containing a
* field "Headers" these will be used as the default headers, so that you don't have to
* to specify per test headers.
* @param info pass in a const DataMap pointer. If no info, it will be set to NULL
*/
virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0;
/** Create a test data object from an index. Helpful for integrating tests with current
* intltest framework which addresses the tests by index.
* @param index index of the test to be instantiated
* @return an instantiated TestData object, ready to provide settings and cases for
* the tests.
*/
virtual TestData* createTestData(int32_t index, UErrorCode &status) const = 0;
/** Create a test data object from a name.
* @param name name of the test to be instantiated
* @return an instantiated TestData object, ready to provide settings and cases for
* the tests.
*/
virtual TestData* createTestData(const char* name, UErrorCode &status) const = 0;
};
class RBTestDataModule : public TestDataModule {
public:
virtual ~RBTestDataModule();
public:
RBTestDataModule(const char* name, TestLog& log, UErrorCode& status);
public:
virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const;
virtual TestData* createTestData(int32_t index, UErrorCode &status) const;
virtual TestData* createTestData(const char* name, UErrorCode &status) const;
private:
UResourceBundle *getTestBundle(const char* bundleName, UErrorCode &status);
private:
UResourceBundle *fModuleBundle;
UResourceBundle *fTestData;
UResourceBundle *fInfoRB;
UBool fDataTestValid;
char *tdpath;
/* const char* fTestName;*/ /* See name */
int32_t fNumberOfTests;
};
#endif

View file

@ -45,7 +45,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /FD /c
# ADD CPP /nologo /G6 /MD /Za /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /FD /c
# ADD CPP /nologo /G6 /MD /Za /W3 /GX /O2 /I "..\..\..\include" /I "..\..\common" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -71,7 +71,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /FD /GZ /c
# ADD CPP /nologo /G6 /MDd /Za /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /FR /FD /GZ /c
# ADD CPP /nologo /G6 /MDd /Za /W3 /Gm /GX /ZI /Od /I "..\..\..\include" /I "..\..\common" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /FR /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
@ -97,7 +97,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN64" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /FD /c
# ADD CPP /nologo /MD /Za /W3 /GX /Zi /O2 /I "..\..\..\include" /D "WIN64" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD CPP /nologo /MD /Za /W3 /GX /Zi /O2 /I "..\..\..\include" /I "..\..\common" /D "WIN64" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win64
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win64
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -107,7 +107,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:IX86 /machine:IA64
# ADD LINK32 /nologo /dll /machine:IA64 /out:"..\..\..\bin\ctestfw.dll"
# ADD LINK32 /nologo /dll /machine:IX86 /out:"..\..\..\bin\ctestfw.dll" /machine:IA64
!ELSEIF "$(CFG)" == "ctestfw - Win64 Debug"
@ -123,7 +123,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN64" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /FD /GZ /c
# ADD CPP /nologo /MDd /Za /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN64" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FR /FD /GZ /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD CPP /nologo /MDd /Za /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /I "..\..\common" /D "WIN64" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CTESTFW_EXPORTS" /D "T_CTEST_IMPLEMENTATION" /D "_IA64_" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FR /FD /GZ /QIA64_fmaopt /Wp64 /Zm600 /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win64
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win64
# ADD BASE RSC /l 0x409 /d "_DEBUG"
@ -133,7 +133,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:IX86 /pdbtype:sept /machine:IA64
# ADD LINK32 /nologo /dll /incremental:no /debug /machine:IA64 /out:"..\..\..\bin\ctestfwd.dll" /pdbtype:sept
# ADD LINK32 /nologo /dll /incremental:no /debug /machine:IX86 /out:"..\..\..\bin\ctestfwd.dll" /pdbtype:sept /machine:IA64
!ENDIF
@ -150,6 +150,18 @@ LINK32=link.exe
SOURCE=.\ctest.c
# End Source File
# Begin Source File
SOURCE=.\datamap.cpp
# End Source File
# Begin Source File
SOURCE=.\testdata.cpp
# End Source File
# Begin Source File
SOURCE=.\tstdtmod.cpp
# End Source File
# End Group
# Begin Group "Header Files"
@ -157,49 +169,26 @@ SOURCE=.\ctest.c
# Begin Source File
SOURCE=.\unicode\ctest.h
# End Source File
# Begin Source File
!IF "$(CFG)" == "ctestfw - Win32 Release"
SOURCE=.\unicode\datamap.h
# End Source File
# Begin Source File
# Begin Custom Build
InputPath=.\unicode\ctest.h
SOURCE=.\unicode\testdata.h
# End Source File
# Begin Source File
"..\..\..\include\unicode\ctest.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\..\include\unicode
SOURCE=.\unicode\testlog.h
# End Source File
# Begin Source File
# End Custom Build
!ELSEIF "$(CFG)" == "ctestfw - Win32 Debug"
# Begin Custom Build
InputPath=.\unicode\ctest.h
"..\..\..\include\unicode\ctest.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\..\include\unicode
# End Custom Build
!ELSEIF "$(CFG)" == "ctestfw - Win64 Release"
# Begin Custom Build
InputPath=.\unicode\ctest.h
"..\..\..\include\unicode\ctest.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\..\include\unicode
# End Custom Build
!ELSEIF "$(CFG)" == "ctestfw - Win64 Debug"
# Begin Custom Build
InputPath=.\unicode\ctest.h
"..\..\..\include\unicode\ctest.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\..\include\unicode
# End Custom Build
!ENDIF
SOURCE=.\unicode\testtype.h
# End Source File
# Begin Source File
SOURCE=.\unicode\tstdtmod.h
# End Source File
# End Group
# Begin Group "Resource Files"