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

OOFTST 22 - common errors

This sample tests some common error conditions that should generate runtime errors
Note: #define OOF_Debug to ensure all errors are trapped 


#include "oofile.h"	// the general oofile library

We start off by declaring a simple class to test.

************* ???? I don't seem to be able to say any more than what's already in the text ehre, so I feel as if this one is incomplete.

DECLARE_CLASS(dbTest22)
	dbChar		f1;
	dbUlong		f2;
	dbReal		f3;  
	  
	dbTest22() : f1(20, "F1", kIndexed),
				f2("F2", kIndexed),
				f3("F3", kIndexed)
{};
	};
  

Here we show a common technique, using our own class to contain all the database

class myDatabase : public TEST_CONNECT
{
public:
	myDatabase();
	~myDatabase();
	  
	dbTest22*     	 dbTest;
};  

This is the constructor for the database class. It creates the database using new.

myDatabase::myDatabase()
{
	dbTest = new dbTest22;
}

This is the destructor for the database class. It removes the database using delete.

myDatabase::~myDatabase()
{
	delete dbTest;
}

  
int main()
{
	cout << "OOFILE Validation Suite - Test 22\n"
		 << "This tests various common errors that should be picked up with\n"
		 << "runtime errors.\n\n";	  

We must always call dbConnect before defining a table, so here we test whether this error will be picked up.

Testing: runtime error check - dbTable before dbConnect

	cout << "Test defining a dbTable object without a preceding dbConnect. \n"
		 <<	"This will also generate complaints from each field in the dbTest22\n\n";
	dbTest22    	 shouldGenerateRuntimeError;

Next we test whether or not it will pick up the error of defining a char without a table being defined first.

Testing: runtime error check - dbChar before dbTable

	cout << "Now test defining a dbChar object without a preceding dbTable:\n\n";
	dbChar    	 shouldAlsoGenerateRuntimeError(20, "dbChar to fail");

***********You can't put a keyword index on an oofchar. This is what is tested here.

Testing: runtime error check - keyword index on oofchar.
 

	cout << "Now test defining a oofChar and saying it has a keyword index:\n\n";
	oofChar	theDate;
	theDate.indexWords();  

We test here if there are problems with declaring a database but not opening it.

Testing: runtime error check - db declared but not opened

	cout << "This tests side effects in declaring a database\n"
		 << "but never opening it. This is legal, but has caused problems in the past\n\n";
	myDatabase*  theDB = new myDatabase;
	  

Now we clear the slate by deleting the database we just created. If any problems occur due to not opening the database, they should occur here.

	delete theDB;
	  
	cout << endl <<"Test Completed" << endl;
	  
	return EXIT_SUCCESS;
}  

 

Feature index

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