Accessing Test Data

The TEFUnit framework provides an interface for accessing .ini files from within your unit tests. The CTestFixture base class has a CTestConfig object (iConfig) which contains the following functions:

TBool GetBool(const TDesC& aSectionName, const TDesC& aKey, TBool& aResult) const;
TBool GetInt(const TDesC& aSectionName, const TDesC& aKey, TInt& aResult) const;
TBool GetHex(const TDesC& aSectionName, const TDesC& aKey, TInt& aResult) const;
TBool GetString(const TDesC& aSectionName, const TDesC& aKey, TPtrC& aResult) const;

// Use the section name passed in via the script
TBool GetBool(const TDesC& aKey, TBool& aResult) const;
TBool GetInt(const TDesC& aKey, TInt& aResult) const;
TBool GetHex(const TDesC& aKey, TInt& aResult) const;
TBool GetString(const TDesC& aKey, TPtrC& aResult) const;

TBool WriteBool(const TDesC& aSectionName, const TDesC& aKey, TBool& aValue) const;
TBool WriteInt(const TDesC& aSectionName, const TDesC& aKey, TInt& aValue) const;
TBool WriteHex(const TDesC& aSectionName, const TDesC& aKey, TInt& aValue) const;
TBool WriteString(const TDesC& aSectionName, const TDesC& aKey, TPtrC& aValue) const;

// Use the section name passed in via the script
TBool WriteBool(const TDesC& aKey, TBool& aValue) const;
TBool WriteInt(const TDesC& aKey, TInt& aValue) const;
TBool WriteHex(const TDesC& aKey, TInt& aValue) const;
TBool WriteString(const TDesC& aKey, TPtrC& aValue) const;

Examples:

// Get an integer from “SectionOne”
TInt theInt = 0;
TBool res = iConfig.GetInt(_L("SectionOne"), _L("TheInt"), theInt);

// Get a boolean from “SectionOne”
TBool theBool = EFalse;
res = iConfig.GetBool(_L("SectionOne"), _L("TheBool"), theBool);

// Get some hex data from “SectionOne”
TInt theHex = 0;
res = iConfig.GetHex(_L("SectionOne"), _L("TheHex"), theHex);

// Get a string from “SectionOne”
TPtrC theString;
res = iConfig.GetString(_L("SectionOne"), _L("TheString"), theString);

// Get another integer from “SectionTwo”
res = iConfig.GetInt(_L("SectionTwo"), _L("TheInt"), theInt);