OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME

OOFTST 30 - standalone field types

This sample tests standalone field types, used with a variety of constructors and simple operations.

See also ooftst05 for a wide variety of date input tests and field descriptions for a general description of each of the field types.


#include "oofile.h"	// the general oofile library  
int 
main()
{
	cout << "OOFILE Validation Suite - Test 30\n"
		 << "Simple test to operations on all the standalone field types"
		 << endl << endl;  

Each of the test sets, below, has been placed into brackets so that all variables are local. This insures a short lifespan for our variables (hinting to the compiler to use registers) and leads to better efficiency. It also means we can call our variables by similar names for each field type we test, for better comparison between the fields.

We will start by testing Date and Time related operations

Here, we change the default date order to Month, Day, Year. This is useful to convert dates from an Australian format to the US format. We do it here, so that we know what order the date is in (initialise it). This is achieved by assigning the date order (dbDate::orderMDY) to dbDate::sDefaultDateOrder.

Testing: set default date order to orderMDY

	cout << "change the default date order to Month, Day Year" << endl;  
	dbDate::sDefaultDateOrder=dbDate::orderMDY;  

oofDate

(see also ooftst05 for dbDate tests)

We will start by creating some constructors for dates.  We are going to test three date fields. The first we initialise to the current date using the function dbDate::currentDate(). The second we will assign the value of the first and the third we will assign a specific value from a string.

Testing: explicit initialisation of oofDate using date function dbDate::currentDate()
Testing: explicit initialisation of oofDate from another oofDate
Testing: implicit initialisation of oofDate using string

	{
	oofDate first;
	first = dbDate::currentDate();
	oofDate second = first;
	oofDate third("Jan 15th '97");

Now we will go through the date operations. We start by subtracting a constant from a date. This should give the effect of removing the given number in days. For this example, we subtract 14 which will produce the date for 2 weeks previous. Note our use of the operator "-=".

Testing: oofDate - subtraction of constant using operator-=

	second -= 14;

Next we will use the increment operator "++". This should give the effect of adding 1 day to the date.

Testing: oofDate - increment using ++operator

	++third;

Now we print out our variables so we can see what difference has been made.

	cout << "\nTesting oofDate:"
		 << "\nToday: " << first 
		 << "\nTwo weeks ago: " << second 
		 << "\nJan 16th '97 " << third 
		 << endl << endl;
	}

oofDateTime

(see also ooftst05 for dbDateTime tests)

{
Now we will initialise some oofDateTime variables. This is done similarly to the oofDate, above. Our first variable is intialised using the dbDateTime::currentTime() function. This returns both the current date and current time to be stored into our variable. The second variable is assgined the value of the first and the third is assigned a value from a string.

Testing: explicit initialisation of oofDateTime using date function dbDateTime::currentTime()
Testing: explicit initialisation of oofDateTime from another oofDateTime
Testing: implicit initialisation of oofDateTime using string

	oofDateTime first;
	first = dbDateTime::currentTime();
	oofDateTime second = first;
	oofDateTime third("Jan 15th '97 3:15 pm");

Next we go through some basic DateTime operations. We start by subtracting a constant from a dateTime. This should give the effect of removing the given number in days, much as the function for oofDate above. For this example, we subtract 14 which will produce the date for 2 weeks previous. Note our use of the operator "-=".

Testing: oofDateTime - subtraction of constant using operator-=

	second -= 14;

Next we will use the increment operator "++". This should give the effect of adding 1 day to the date half of the dateTime.

Testing: oofDateTime - increment using ++operator

	++third;

Now we will print out our results to see how they changed.

	cout << "\nTesting oofDateTime:"
		 << "\nToday: " << first 
		 << "\nTwo weeks ago: " << second 
		 << "\nJan 16th '97 3:15 pm " << third 
		 << endl << endl;
	}

oofTime

(see also ooftst05 for dbTime tests)

	{

We will start by initialising three oofTime variables in a similar way to the oofDateTime above. Our first variable is intialised using the dbTime::currentTime() function. This returns the current time to be stored into our variable. The second variable is assgined the value of the first and the third is assigned a value from a string.

Testing: explicit initialisation of oofTime using date function dbTime::currentTime()
Testing: explicit initialisation of oofTime from another oofTime
Testing: implicit initialisation of oofTime using string

	oofTime first;
	first = dbTime::currentTime();
	oofTime second = first;
	oofTime third("3:15:45.32 pm");

Next we go through some basic time operations. We start by subtracting a constant fromour time variable. This should give the effect of removing the given number in milliseconds. For this example, we subtract 3000 which will produce the date for 3 seconds previous. Note our use of the operator "-=".

Testing: oofTime - subtraction of constant using operator-=

	second -= 3000;  

Next we will use the increment operator "++". This should give the effect of adding 1 second to the time.

Testing: oofTime - increment using ++operator

	++third;

And now we print them out.

	cout << "\nTesting oofTime:"
		 << "\nNow: " << first 
		 << "\n3000 milliseconds (3 seconds) earlier: " << second 
		 << "\n3:15:46.32 pm" << third 
		 << endl << endl;
	}	  

Now we move on to string based operations.

oofText

	{

First we declare 4 text variables. Our first variable is initialised explicitly with a string, the second is initialised with the value of the first, the third variable is initialised implicitly with a string and the fourth is left blank (to test appending to an empty string). Note that we don't specify a length, it defaults to 80.

Testing: explicit initialisation of oofText with string
Testing: explicit initialisation of oofText from another oofText
Testing: implicit initialisation of oofText with string

	oofText first;
	first = "Hi There";
	oofText second = first;
	oofText third("Jan 15th '97");
	oofText fourth;

Now we test the various text appending operations. First we try appending a character, then a string.

Testing: oofText append using operator+=
Testing: oofText append - char
Testing: oofText append - string

	second += ' ';	
	second += "Andy";

Then we test the pathalogical case, by trying to append an empty string to our non-empty oofText

Testing: oofText append - empty string

	second += "";	

Lastly, we try to append a string to an empty string.

Testing: oofText append - string onto an empty oofText

	fourth += "appended to empty";

And now we print our results. 

	cout << "\nTesting oofText:"
		 << "\n'Hi There' " << first 
		 << "\n'Hi There Andy' " << second 
		 << "\n'Jan 15th '97' " << third 
		 << "\n'appended to empty' " << fourth 
		 << endl << endl;
	}  

OOF_String (also oofString)

	{

Note: OOF_String is our simple string type, NOT a database type, this is why it does not follow the naming conventions for the previous types. A typedef oofString has been provided and is the preffered usage for this object type.

We start by initialising several variables. Our first is explicitly initialised with a given string. The second is assigned the value of the first. The third is initialised implicitly from a given string. The fourth is to be kept uninitialised so we can test appending to an empty string. The fifth, sixth and seventh will be initialised by other functions later.

Testing: explicit initialisation of OOF_String with string
Testing: explicit initialisation of OOF_String from another OOF_String
Testing: implicit initialisation of OOF_String with string

	OOF_String first; 
	first = "Hi There";
	OOF_String second = first;
	OOF_String third("Jan 15th '97");
	OOF_String fourth;	// test append to empty
	OOF_String fifth, sixth, seventh;

Now we test the string append operations. We try appending a character, then a string.

Testing: OOF_String append using operator+=
Testing: OOF_String append - char
Testing: OOF_String append - string

	second += ' ';	
	second += "Andy";

Then we test the pathalogical case, by trying to append an empty string to our non-empty string

Testing: OOF_String append - empty string

	second += "";	

Next we try to append a string to an empty string.

Testing: OOF_String append - string onto an empty OOF_String

	fourth += "appended to empty";

Now we will test some conversion operations. When passed a number (of various types), this will then initialise the string to be the string of that number (eg the number 12 becomes the string "12"). Note that we use the same function call for each of the different number types (operator overloading).

Our first two tests are to convert an integer and then a floating point value.

Testing: number to OOF_String conversion - integer
Testing: number to OOF_String conversion - float

	fifth.convertNumber(12345);
	sixth.convertNumber(123.456);

Next, test the ability to pass in a formatted string. In this case, we pass in the string "printf test: %d". The %d will be replaced with the given number.

Testing: number to OOF_String conversion -formatted string with integer

	seventh.convertNumber(123456, "printf test: %d");

Now we print out our strings to see how they are now.

	cout << "\nTesting OOF_String simple string class:"
		 << "\n'Hi There' " << first 
		 << "\n'Hi There Andy' " << second 
		 << "\n'Jan 15th '97' " << third 
		 << "\n'appended to empty' " << fourth 
		 << "\n'123456' " << fifth 
		 << "\n'123.456' " << sixth 
		 << "\n'printf test: 123456' " << seventh 
		 << endl << endl;
	}

oofChar

	{

First we declare 4 char variables. Our first variable is initialised explicitly with a string, the second is initialised with the value of the first, the third variable is initialised implicitly with a string and the fourth is left blank (to test appending to an empty char variable). Note that we don't specify a length, it defaults to 80.

Testing: explicit initialisation of oofChar with string
Testing: explicit initialisation of oofChar from another oofChar
Testing: implicit initialisation of oofChar with string

	oofChar first; 
	first = "Hi There";
	oofChar second = first;
	oofChar third("Jan 15th '97");
	oofChar fourth;	

Now we test the various text appending operations. First we try appending a character, then a string.

Testing: oofChar append using operator+=
Testing: oofChar append - char
Testing: oofChar append - string

	second += ' ';	
	second += "Andy";

Then we test the pathalogical case, by trying to append an empty string to our non-empty oofChar

Testing: oofChar append - empty string

	second += "";	

Lastly, we try to append a string to an empty string.

Testing: oofChar append - string onto an empty oofChar

	fourth += "appended to empty";

And now we print our results. 

	cout << "\nTesting oofChar:"
		 << "\n'Hi There' " << first 
		 << "\n'Hi There Andy' " << second 
		 << "\n'Jan 15th '97' " << third 
		 << "\n'appended to empty' " << fourth 
		 << endl << endl;
	}

Now we move on to the numerical fields.

oofUshort

	{

First we declare three unsigned short variables. Our first variable is initialised explicitly with an integer, the second is initialised with the value of the first, and the third variable is initialised implicitly with an integer.

Testing: explicit initialisation of oofUshort with integer
Testing: explicit initialisation of oofUshort from another oofUshort
Testing: implicit initialisation of oofUshort with integer

	oofUshort first; 
	first = 99;
	oofUshort second = first;
	oofUshort third(1001);

Our test consists of adding a small integer to one of the variables.

Testing: oofUshort addition of small integer

	second  = second + 2;

Now we print our variables. 

	cout << "\nTesting oofUshort:"
		 << "\n'99' " << first 
		 << "\n'101' " << second 
		 << "\n'1001' " << third 
		 << endl << endl;
	}

oofShort

	{

First we declare our three short variables. Our first variable is initialised explicitly with a negative integer, the second is initialised with the value of the first, and the third variable is initialised implicitly with a positive integer.

Testing: explicit initialisation of oofShort with +ve integer
Testing: explicit initialisation of oofShort from another oofShort
Testing: implicit initialisation of oofShort with -ve integer

	oofShort first; 
	first = -99;
	oofShort second = first;
	oofShort third(1001);

Our test consists of subtracting a small integer from one of the variables.

Testing: oofShort subtraction of small integer

	second  = second - 2;

Our variables are ready for printing. 

	cout << "\nTesting oofShort:"
		 << "\n'-99' " << first 
		 << "\n'-101' " << second 
		 << "\n'1001' " << third 
		 << endl << endl;
	}

oofUlong

	{

First we declare our three unsigned long variables. Our first variable is initialised explicitly with an integer, the second is initialised with the value of the first, and the third variable is initialised implicitly with an integer.

Testing: explicit initialisation of oofUlong with integer
Testing: explicit initialisation of oofUlong from another oofUlong
Testing: implicit initialisation of oofUlong with integer

	oofUlong first; 
	first = 99;
	oofUlong second = first;
	oofUlong third(1000001);

Our test consists of adding a small integer to one of the variables.

Testing: oofUlong addition of small integer

	second  = second + 2;

Now we print the results.

	cout << "\nTesting oofUlong:"
		 << "\n'99' " << first 
		 << "\n'101' " << second 
		 << "\n'1000001' " << third 
		 << endl << endl;
	}

oofLong

	{

First we declare our unsigned long variables. Our first variable is initialised explicitly with a negative integer, the second is initialised with the value of the first, and the third variable is initialised implicitly with a positive integer.

Testing: explicit initialisation of oofLong with -ve integer
Testing: explicit initialisation of oofLong from another oofLong
Testing: implicit initialisation of oofLong with +ve integer

	oofLong first; 
	first = -99;
	oofLong second = first;
	oofLong third(1000001);

Our test consists of subtracting a small integer from one of the variables.

Testing: oofLong subtraction of small integer

	second  = second - 2;

Now we print our variables to see how they have changed. 

	cout << "\nTesting oofLong:"
		 << "\n'-99' " << first 
		 << "\n'-101' " << second 
		 << "\n'1000001' " << third 
		 << endl << endl;
	}

oofReal

	{

Reals are floating point variables and we are going to start by initialising 3 of them. Our first variable is initialised explicitly with a negative real value, the second is initialised with the value of the first, and the third variable is initialised implicitly with a positive real value.

Testing: explicit initialisation of oofReal with -ve real value
Testing: explicit initialisation of oofReal from another oofReal
Testing: implicit initialisation of oofReal with +ve real value

	oofReal first; 
	first = -0.99;
	oofReal second = first;
	oofReal third(1000001);

Our test consists of subtracting a small real value from one of the variables.

Testing: oofReal subtraction of small real value

	second  = second - 0.02;

Now we print our variables. 

	cout << "\nTesting oofReal:"
		 << "\n'-0.99' " << first 
		 << "\n'-1.01' " << second 
		 << "\n'1000001' " << third 
		 << endl << endl;
	}

Here we test the boolean variable type.

oofBool

	{

First we initialise a few variables. The first is explicitly initialised to true, the second is assigned the value of the first, the third is implicitly initialised the value of true by passing in the string "True", the fourth is implicitly initialised by passing in the character 'N' and the fifth is left empty to initialise later.

Testing: explicit initialisation of oofBool with boolean value
Testing: explicit initialisation of oofBool from another oofBool
Testing: implicit initialisation of oofBool with string
Testing: implicit initialisation of oofBool with character ('N')

	oofBool first; 
	first = true;
	oofBool second = first;
	oofBool third("True");
	oofBool fourth('N');
	oofBool fifth;

Now we test a few boolean operations. Our first operation is the NOT operation -> this will give the opposite of whatever the oofBool currently is.

Testing: oofBool operator!

	second  = !second;

Now we try assigning various values to our fifth variable. We start by assigning a character, then the integer 0 (false) and then the integer 1 (often used value for true). Note that any non-zero value is counted as true, so if testing a boolean variable it is better to test for falsity (false is always 0) or to explicitly use the word true.

	fifth = 'T';	
	fifth = 0;	
	fifth = 1;

Now we print out our boolean variables.

	cout << "\nTesting oofBool:"
		 << "\n'T' " << first 
		 << "\n'F' " << second 
		 << "\n'T' " << third 
		 << "\n'F' " << fourth 
		 << "\n'T' " << fifth 
		 << endl << endl;
	}

Lastly, we test the BLOB -> a binary buffer.

oofBLOB

	{

First, we declare an array of numbers, initialising it with integers in both decimal and in hexadecimal configuration. We also declare another variable, initialising it with the size of our array.

	long testBuf[] = {0, 2, 4, 8, 16, 65535, 0xADADADAD};
	long bufLen = sizeof(testBuf);

Then we declare our first BLOB.

	oofBLOB first;

We initialise our BLOB by using the setBytes() function and passing it the array and its length.

Testing: function setBytes() on oofBLOB

	first.setBytes(testBuf, bufLen);

We initialise our second variable by assigning it the value of the first.

Testing: explicit initialisation of oofBLOB from another oofBLOB

	oofBLOB second = first;

Our third BLOB is left empty so we can test aooending to an empty BLOB.

	oofBLOB third;

We then test the append functions. Starting by appending the first BLOB to the second, using the operator "+=".

Testing: oofBLOB append using operator+=
Testing: oofBLOB append - oofBLOB

	second += first;

Now we try append using the function append(). Note that we must pass in both our array and the variable containing its length.

Testing: oofBLOB append using function append()
Testing: oofBLOB append - long array

	third.append(testBuf, bufLen);

Now we print out our BLOBs.

	cout << "\nTesting oofBLOB:"
		 << "\n'0, 2, 4, 8, 16, 65535, 0xADADADAD'\n" << first 
		 << "\nsame as above, twice\n" << second 
		 << "\nsame as first\n" << third 
		 << endl << endl;
	}

Field types and dbViews

Lastly, we will demonstrate using standalone fields in a dbView. This technique is mainly used for report-writers.

Note the use of either a pointer or temporary object. The pointer will be adopted by the view, and the temporary copied

	dbView  justOneLook;
	justOneLook << "This is a text string, which will be automatically attached as an oofChar"
		<< new oofReal(12.3)  << dbDate::currentDate();
	cout << justOneLook;
			  
	cout << endl << "done" << endl;
	return EXIT_SUCCESS;
}        

 

Feature index

(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001