/////////////////////////////////////////////////////////////// // UTDE2.CPP - unit test #2 for dupsExec module // // ver 1.0 // // // // Language: Visual C++, ver 6.0 // // Platform: Micron Dual Pentium 200, Windows NT 4.0 // // Application: CSE784 - Software Studio, Testing // // Author: Jim Fawcett, CST 2-187, (315) 443-3948 // // fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// /* Functions Tested: ================= 1. Compiler Generated Constructor - dupsProc::dupsProc() Allocated Requirements - None Processing Requirements: Create an instance of the dupsProc class. 2. Accessor for member variable startDir - dupsProc::startPath() Allocated Requirements - None Processing Requirements: Set and retrieve the starting path. 3. duplicates display function - dupsProc::display(displayType dt) Allocated Requirements: 3.1.4.2.2.a - The display process shall extract all of the duplicate filenames and their associated paths from the file and path storage and present them to the user via standard output. 3.1.4.2.2.b - The format used shall list each duplicated file name followed by a list of all the paths where it is found. 3.1.4.2.2.c - Each path name shall be preceded by the size and time and date of last modification for the file on that path. // Test Description: ================= This test demonstrates creation of a dupsProc object by a compiler generated constructor, accessing of the starting path, and display- ing duplicates information collected during directory searching. These are all the functions belonging to the dupsExec module shown on the first of the dupsExec structure charts. Test Procedure: =============== - Create a unit test directory and copy into it the files: utde2.cpp, dupsExec.cpp, nav.h, nav.cpp, fileStor.h, and fileStor.cpp. - Create a unit test project containing the files utde2.cpp, nav.h, nav.cpp, fileStor.h, fileStor.cpp. Note that dupsExec.cpp is not part of the project, but is included by utde2.cpp. - in Project\Settings\C/C++\Preprocessor Definitions: add the definition UNITTEST_DE2 ---------------------------------------------- Test UTDE2a - dupsProc::dupsProc() constructor ---------------------------------------------- This test has no dependencies on earlier testing. Start debugger and single step through the main function included in this file. Observe that the a dupsProc object, dp, is created. The debugger can not step into constructor code since no source code for this function exists. Examine dupsProc class declaration in dupsExec.cpp and note that no system resources are used by the class, e.g., heap memory, database locks, mutex objects, ... The only data members are three strings and one fileStor object. Each of these has correct void construction semantics so the compiler generated dupsProc constructor will operate correctly. ----------------------------------- Test UTDE2b - dupsProc::startPath() ----------------------------------- This test has no dependencies on earlier testing. Restart the debugger and single step through the main function in this file. Observe that a start path is assigned in the first invocation of the startPath() function. Examine string startDir contents to observe that it contains the assigned name. Continue single stepping and observe that the same name is extracted in the next statement and stored in the variable seeName in the main func- tion in this file. // ----------------------------------------------- Test UTDE2c - dupsProc::display(displayType dt) ----------------------------------------------- This test depends on the correct operation of functions tested in UTDE1 and UTFS1. Continue single stepping through the main function in this file. Note that several fictitious file names and path names are entered into the fileStor object via the functions dupsProc::dirsProc(...) and dupsProc::fileProc(...). Step over the invocation of dupsProc::display(...) and observe that all duplicates are identified and displayed with their corresponding paths per requirements, 3.1.4.2.2.a and 3.1.4.2.2.b The functionality of requirement 3.1.4.2.2.c has not yet been implemented. Restart the debugger and single step into first invocation of the function dupsProc::display(...). - Note that the display type dt is all. - Observe that a reference to a fileMap object is returned from the dupsProc::fileStor object. - Observe that an iterator into the fileMap object is created and used to search through the entire Map in the for-loop starting just below the iterator declaration. - Single step through the loop for every iteration: - Observe that files first_file, second_file, third_file, fourth_file, fifth_file, and sixth_file, installed at beginning of this test, are accessed and displayed. - Observe that for each file name accessed its associated iterator list is searched for iterators into the pathSet. - Observe that an iterator into the iterator list is created and used to search through the entire iterator list in the for-loop starting just below the iterator declaration. - Observe that the following paths are accessed: first_file - first_dir, second_dir, third_dir second_file - first_dir, second_dir third_file - first_dir, second_dir, third_dir fourth_file - first_dir fifth_file - first_dir, third_dir sixth_file - third_dir - Observe that each each accessed path is displayed. - Observe that the inner iteration through the path list terminates. - Observe that the outer iteration through the file map terminates. */ // /* Continue single stepping into second invocation of dupsProc::display(). - Note that the display type dt is dups. - Observe that a reference to a fileMap object is returned from the dupsProc::fileStor object. - Observe that an iterator into the fileMap object is created and used to search through the entire Map in the for-loop starting just below the iterator declaration. - Single step through the loop for every iteration: - Observe that every file list is tested for length greater than one, e.g., there is more than one path associated with this file, e.g., this file name is duplicated in the directory tree. - Observe that first_file, second_file, third_file, and fifth_file are accessed and displayed. - Observe that for each file name accessed its associated iterator list is searched for iterators into the pathSet. - Observe that an iterator into the iterator list is created and used to search through the entire iterator list in the for-loop starting just below the iterator declaration. - Observe that the following paths are accessed: first_file - first_dir, second_dir, third_dir second_file - first_dir, second_dir third_file - first_dir, second_dir, third_dir fifth_file - first_dir, third_dir - Observe that each each accessed path is displayed. - Observe that the inner iteration through the path list terminates. - Observe that the outer iteration through the file map terminates. */ // #include "dupsExec.cpp" // never include .cpp files in other source // files except test drivers void main() { //----< test UTDE2a >------------------------------------------ dupsProc dp; //----< test UTDE2b >------------------------------------------ dp.startPath() = "d:\\first\\Dir\\To\\Search"; string seeName = dp.startPath(); //----< test UTDE2c >------------------------------------------ // create artificial path names and file names and store in fileStor // object via dupsProc::fileProc(...) and dupsProc::dirsProc(...), // respectively WIN32_FIND_DATA fd; dp.dirsProc("first_dir"); strcpy(fd.cFileName,"first_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"second_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"third_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"fourth_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"fifth_file.cpp"); dp.fileProc(&fd); dp.dirsProc("second_dir"); strcpy(fd.cFileName,"first_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"second_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"third_file.cpp"); dp.fileProc(&fd); dp.dirsProc("third_dir"); strcpy(fd.cFileName,"first_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"third_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"fifth_file.cpp"); dp.fileProc(&fd); strcpy(fd.cFileName,"sixth_file.cpp"); dp.fileProc(&fd); // display contents of fileStor object dp.display(dupsProc::all); // display duplicates from contents of fileStor object dp.display(dupsProc::dups); cout << endl; }