//////////////////////////////////////////////////////////////////////////// // SingleTestUtil.cpp : single test class for CodeUtilities pkg // // ver 1.0 // // // // Application : OOD F18 Project 2 Help // // Platform : VS17 Community - Windows 10 Professional x64 // // Author : Ammar Salman, EECS Department, Syracuse University // // 313/788-4694, hoplite.90@hotmail.com // //////////////////////////////////////////////////////////////////////////// /* * Package description: * ====================== * This is a 'single test' test driver DLL package. It follows the same * protocol defined in ITest.h package. For DllLoader, it doesn't care * if the TestDriver contains one or many Test Classes as it will attempt * to get the collection of ITest*. * * Required files: * ================= * ITests.h SingleTestUtil.cpp CodeUtilities.h * * Maintainence History: * ======================= * ver 1.0 - first release */ #define IN_DLL #define ARG_SIZE 256 // for the manufactured cmd args #include "../ITests.h" #include "../CodeUtilities/CodeUtilities.h" #include #include #include using namespace Utilities; using namespace std; // the concrete Test class that implements ITest // it performs tests on ProcessCmdArgs and Convereter classes in a single test class class SingleTestUtilities : public ITest { public: DLL_DECL bool test(); DLL_DECL std::string name(); DLL_DECL std::string author(); }; DLL_DECL bool SingleTestUtilities::test() { cout << "\n Testing ProcessCmdLine class"; cout << "\n =============================="; // create arguments for testing int argc = 4; char ** argv = new char*[argc]; for (int i = 0; i < argc; ++i) { argv[i] = new char[ARG_SIZE]; } strcpy_s(argv[0], ARG_SIZE, "dummy.exe"); strcpy_s(argv[1], ARG_SIZE, "../"); strcpy_s(argv[2], ARG_SIZE, "\\s"); strcpy_s(argv[3], ARG_SIZE, "\"*.h *.cpp\""); cout << "\n\n Arguments:"; for (int i = 0; i < argc; i++) { cout << "\n arg #" << i << ":\t" << argv[i]; } ProcessCmdLine pcl(argc, argv); cout << "\n\n Extracted information:"; cout << "\n Path:\t" << pcl.path(); cout << "\n Options:\t"; for (auto opt : pcl.options()) cout << opt << " "; cout << "\n Patterns:\t"; for (auto pat : pcl.patterns()) cout << pat << " "; for (int i = 0; i < argc; i++) delete[] argv[i]; delete[] argv; cout << "\n\n\n Testing Converter class"; cout << "\n ========================="; cout << "\n Converting from string \"10\" to integer"; cout << "\n Converted number: \"" << Converter::toValue("10"); cout << "\n\n Converting from integer 10 to string"; cout << "\n Converted string: \"" << Converter::toString(10) << "\""; return true; } DLL_DECL std::string SingleTestUtilities::name() { return string("CodeUtilities single Test DLL"); } DLL_DECL std::string SingleTestUtilities::author() { return string("Ammar"); } ////////////////////////////////////////////////////////////////////////////// // test collection class TestCollection : public ITests { DLL_DECL std::vector tests(); }; DLL_DECL std::vector TestCollection::tests() { std::vector tests_vec; tests_vec.push_back(new SingleTestUtilities); return tests_vec; } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // this section is where each Test Driver DLL completely differs from other // test drivers. Although the same name can be used in all TestDrivers, the // actual instance of TestCollection is different in the way it returns // different collection of ITest*. DLL_DECL ITests* get_ITests() { return new TestCollection; }