/////////////////////////////////////////////////////////////// // // // utstr1.cpp - unit test str constructors, destructor // // // // Source: strs.hpp, strs.cpp v4.4 // // Author: Jim Fawcett, x2654, jfawcett@neptune // // // /////////////////////////////////////////////////////////////// // // // Files needed: // // utstr1.cpp, strs.hpp, strs.cpp // // // // Build command: // // bc utstr1.cpp // // - sets up test driver for debugger walkthrough // // inside integrated development environment // // - single step through tests, tracing into each // // invoked function // // // // Note: utstr1.cpp includes the other files so // // no project file is needed // // // /////////////////////////////////////////////////////////////// // // // Maintenance History: // // v1.0 - 16 Oct 94 // // . tests created // // // /////////////////////////////////////////////////////////////// // // // Signature indicates tests were all run and verified // // all expected results. // // // // // // Signature: Date: // // -------------------------- ----------- // // // /////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////// // // // utstr1.cpp - unit test #1a // // str(), void constructor // // // // Source: strs.hpp, strs.cpp v4.4 // // Author: Jim Fawcett, x2654, jfawcett@neptune // // // /////////////////////////////////////////////////////////////// // // // Preconditions: // // none // // Derived requirements: // // - create object with null string value and default // // static parameters // // // /////////////////////////////////////////////////////////////// // // // Test Procedure - test by inspection // // - verify that all static data members are initialized // // to null or default values // // - verify that all non-static data members are given // // null values // // // // Expected test results: Results verified: // // - lextype set to getlines - // // bytes_alloc set to 0 - // // inBuff set to 0 - // // INBUFFSIZE set to 128 - // // - smax set to 0 - // // slen set to 0 - // // shead set to 0 - // // // /////////////////////////////////////////////////////////////// // // // Signature: Date: // // -------------------------- ----------- // // // /////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////// // // // utstr1.cpp - unit test #1b // // str(const str& s), copy constructor // // // // Source: strs.hpp, strs.cpp v4.4 // // Author: Jim Fawcett, x2654, jfawcett@neptune // // // /////////////////////////////////////////////////////////////// // // // Preconditions: // // - sufficient stack space for stack frame containing s // // - sufficient heap space for constructed str values // // Note: // // These conditions apply to all member functions and // // will not be repeated. // // Derived requirements: // // - create object which is clone of an existing str // // . a unique copy of existing string values is created // // in smallest possible allocated heap space // // . physical size is set to allocated size minus one // // . bytes_alloc is increased by allocation // // . slen is set to length of existing str object // // // /////////////////////////////////////////////////////////////// // // // Test Procedure - test by debugger walkthrough // // - use null str, filled str, and partially filled str // // as inputs // // - watch slen, s.slen, smax, s.smax, (char*)shead, // // (char*)s.shead, bytes_alloc in strAlloc(int) // // // // Expected test results: Results verified // // - smax set to s.slen - // // - slen set to s.slen - // // - shead[i] == s.shead[i], i=0..slen - // // // /////////////////////////////////////////////////////////////// // // // Signature: Date: // // -------------------------- ----------- // // // /////////////////////////////////////////////////////////////// #include "strs.hpp" #include "strs.cpp" void main() { // test copy construction from null str str tst1b1; str tst1b2 = tst1b1; // test copy construction from filled str str tst1b3 = "this is a string"; str tst1b4 = tst1b3; // test copy construction from partially filled str str tst1b5(' ',20); tst1b5 = tst1b3; str tst1b6 = tst1b5; // /////////////////////////////////////////////////////////////// // // // utstr1.cpp - unit test #1c // // str(const char* s), promotion constructor // // // // Source: strs.hpp, strs.cpp v4.4 // // Author: Jim Fawcett, x2654, jfawcett@neptune // // // /////////////////////////////////////////////////////////////// // // // Preconditions: // // - none // // Derived requirements: // // - create object which is clone of an C string // // . a unique copy of existing string values is created // // in smallest possible allocated heap space // // . physical size is set to string length plus one // // . slen is set to number of characters // // // /////////////////////////////////////////////////////////////// // // // Test Procedure - test by debugger walkthrough // // - use null string, non-null string as inputs // // - watch slen, smax, (char*)shead, (char*)s // // // // Expected test results: Results verified // // - smax set to strlen(s) - // // - slen set to strlen(s) - // // - shead[i] == s[i], i=0..slen - // // // /////////////////////////////////////////////////////////////// // // // Signature: Date: // // -------------------------- ----------- // // // /////////////////////////////////////////////////////////////// // test copy construction from null string char* tst1c1 = 0; str tst1c2 = tst1c1; // test copy construction from non-null string char* tst1c3 = "this is a string"; str tst1c4 = tst1c3; // /////////////////////////////////////////////////////////////// // // // utstr1.cpp - unit test #1d // // str(const char ch, const int len) // // // // Source: strs.hpp, strs.cpp v4.4 // // Author: Jim Fawcett, x2654, jfawcett@neptune // // // /////////////////////////////////////////////////////////////// // // // Preconditions: // // - none // // Derived requirements: // // - create object which is a specified size and filled // // with a specified character // // . a unique set of identical characters is created // // in allocated heap space // // . physical size is set to number of chars plus one // // . slen is set to number of characters // // // /////////////////////////////////////////////////////////////// // // // Test Procedure - test by debugger walkthrough // // - use array of '\0' and '\a' as inputs // // - watch slen, smax, (char*)shead // // - call repeatedly to exhaust dynamic memory // // // // Expected test results: Results verified // // - smax set to len - // // - slen set to len - // // - shead[i] == ch, i=0..slen - // // - call strAlloc and abort when - // // when dynamic memory is exhausted // // // /////////////////////////////////////////////////////////////// // // // Signature: Date: // // -------------------------- ----------- // // // /////////////////////////////////////////////////////////////// // test construction of str from specification of size and // fill character set to null str tst1d1('\0',8); // test construction of str from specification of size and // non-null fill character str tst1d2('a',10); // test construction of str from negative size str tst1d3('a',0); // makes 0 length str // generates error message str tst1d4('a',-1); // makes 0 length str /* these instructions will allocate memory until exhausted str tst1d5('a',10000); str tst1d6('a',10000); str tst1d7('a',10000); str tst1d8('a',10000); str tst1d9('a',10000); str tst1d10('a',10000); // causes abort */ // /////////////////////////////////////////////////////////////// // // // utstr1.cpp - unit test #1e // // ~str(void) destructor // // // // Source: strs.hpp, strs.cpp v4.4 // // Author: Jim Fawcett, x2654, jfawcett@neptune // // // /////////////////////////////////////////////////////////////// // // // Preconditions: // // - existing object to destruct // // Derived requirements: // // - return system resourses claimed by destroyed object // // . if object has non null heap allocation then // // delete it and decrement bytes_alloc by smax+1 // // . reset shead, smax, and slen to zero // // // /////////////////////////////////////////////////////////////// // // // Test Procedure - test by debugger walkthrough // // - test both null and non-null objects // // - watch slen, smax, (char*)shead, bytes_alloc // // // // Expected test results: Results verified // // - smax set to zero - // // - slen set to zero - // // - shead set to zero - // // - heap memory pointed to by shead - // // deleted using [] // // // /////////////////////////////////////////////////////////////// // // // Signature: Date: // // -------------------------- ----------- // // // /////////////////////////////////////////////////////////////// // create a string to destroy str tst1e1 = "this is a string"; // destroy it tst1e1.~str(); // create null object str* ptr = new str; // and destroy it ptr->str::~str(); // dummy statement to keep debugger active at end of last destruct str temp; }