main.cpp #3

  • //
  • guest/
  • ShadauxCat/
  • Sprawl/
  • Mainline/
  • UnitTests/
  • main.cpp
  • View
  • Commits
  • Open Download .zip Download (2 KB)
//Use STL here because unit tests by default should not trust our own code.
#include <vector>
#include <string>
#include <tuple>
#include <string.h>

int main(int argc, char* argv[])
{
	std::vector<std::tuple<std::string, bool, bool(*)(void)>> tests;

#define ADD_TEST(name) extern bool test_##name(); tests.push_back(std::make_tuple(#name, false, &test_##name))

	ADD_TEST(memory);
	ADD_TEST(hashmap);
	ADD_TEST(list);
	ADD_TEST(string);
	ADD_TEST(json);
	ADD_TEST(time);
	ADD_TEST(thread);
#ifdef WITH_MONGO
	ADD_TEST(mongo_replicable);
#endif

	char validArguments[512];
	validArguments[0] = '\0';

	bool all = false;

	for(auto& test : tests)
	{
		sprintf(validArguments, "%s --%s", validArguments, std::get<0>(test).c_str());
	}

	if(argc <= 1)
	{
		all = true;
	}

	for(int i = 1; i < argc; ++i)
	{
		if(!strcmp(argv[i], "--all"))
		{
			all = true;
			continue;
		}

		bool found = false;

		for(auto& test : tests)
		{
			char arg[64];
			sprintf(arg, "--%s", std::get<0>(test).c_str());
			if(!strcmp(argv[i], arg))
			{
				std::get<1>(test) = true;
				found = true;
				break;
			}
		}

		if(!found)
		{
			printf("Invalid argument ignored: %s\n", argv[i]);
			printf("Valid arguments: %s --all\n", validArguments);
		}
	}

	int exitcode = 0;

	for(auto& test : tests)
	{
		if(all || std::get<1>(test))
		{
			printf("Running test '%s'... ", std::get<0>(test).c_str());
			if(std::get<2>(test)())
			{
				puts("Success!");
			}
			else
			{
				++exitcode;
				puts("FAILED!");
			}
		}
	}
	fflush(stdout);
	return exitcode;
}
# Change User Description Committed
#7 14144 ShadauxCat Switching unit tests to gtest.
100 is a decent number of tests to start with, but it needs to be more like 400 to test the current codebase.

#review-14145
#6 14100 ShadauxCat -Added Deque implementation using circular buffer.
-Fixed List::Insert() and ForwardList::Insert() inserting after the iterator instead of before it. Adjusted the unit tests to compensate.
-Fixed a couple of small vector bugs

#review-14101
#5 14092 ShadauxCat Added BitSet (statically sized at compile time) and corresponding unit test.
BitVector (dynamically sized to the largest input it receives) to come next.

#review-14093
#4 14091 ShadauxCat -Created Vector class, iterator, and unit test
-Made list iterator a bidirectional iterator when created from a doubly-linked list. (It still has operator-- when created from singly-linked list, but it won't compile if it's used.)
-Changed front() and back() in list classes to Front() and Back()

#review-14083
#3 12508 ShadauxCat -Added threading library.
Currently only functional for Linux; Windows will fail to link. (I will fix this soon.)
-Fixed missing move and copy constructors in List and ForwardList
-Fixed broken move constructor in HashMap
-Fixed missing const get() in HashMap
-Fixed broken operator-> in ListIterator
-Added sprawl::noncopyable
-Added sketch headers for filesystem library
-Made StringLiteral hashable, added special hashes for pointers and integers in murmur3
-Fixed compiler warning in async_network
-Updated memory allocators to use new threading library for mutexes
-Added accessibility to sprawl::StringLiteral to be able toa ccess its pointer and length and perform pointer comparisons

#review-12504
#2 11500 ShadauxCat Added sprawl::time library.
Fixed JSON Unit Test bug.
#1 11496 ShadauxCat Initial checkin: Current states for csbuild and libSprawl