git repos / blockattack-game

blame: source/misc/embedded_libs/PlatformFolders-4.2.0/test/tester.cpp

normal view · raw

c74066db Poul Sander 2022-02-16 12:14 1
#include "tester.hpp"
c74066db Poul Sander 2022-02-16 12:14 2
c74066db Poul Sander 2022-02-16 12:14 3
#include <cstdlib>
c74066db Poul Sander 2022-02-16 12:14 4
#include <iostream>
c74066db Poul Sander 2022-02-16 12:14 5
#include <stdexcept>
c74066db Poul Sander 2022-02-16 12:14 6
#include <string>
c74066db Poul Sander 2022-02-16 12:14 7
#include <vector>
c74066db Poul Sander 2022-02-16 12:14 8
c74066db Poul Sander 2022-02-16 12:14 9
// This should be passed either be char* or std::string for this to work
c74066db Poul Sander 2022-02-16 12:14 10
static void test_internal(const std::string& data) {
c74066db Poul Sander 2022-02-16 12:14 11
	try {
c74066db Poul Sander 2022-02-16 12:14 12
		// Check that it actually got anything
c74066db Poul Sander 2022-02-16 12:14 13
		if (data.empty()) {
c74066db Poul Sander 2022-02-16 12:14 14
			throw std::logic_error("Got empty data");
c74066db Poul Sander 2022-02-16 12:14 15
		}
c74066db Poul Sander 2022-02-16 12:14 16
	}
c74066db Poul Sander 2022-02-16 12:14 17
	catch (const std::exception& e)   {
c74066db Poul Sander 2022-02-16 12:14 18
		// Take any standard exception & output its message
c74066db Poul Sander 2022-02-16 12:14 19
		std::cerr << e.what() << std::endl;
c74066db Poul Sander 2022-02-16 12:14 20
		std::exit(EXIT_FAILURE);
c74066db Poul Sander 2022-02-16 12:14 21
	}
c74066db Poul Sander 2022-02-16 12:14 22
	catch (...)   {
c74066db Poul Sander 2022-02-16 12:14 23
		// If any non-std exception is thrown, also fail
c74066db Poul Sander 2022-02-16 12:14 24
		std::cerr << "Unknown exception!" << std::endl;
c74066db Poul Sander 2022-02-16 12:14 25
		std::exit(EXIT_FAILURE);
c74066db Poul Sander 2022-02-16 12:14 26
	}
c74066db Poul Sander 2022-02-16 12:14 27
}
c74066db Poul Sander 2022-02-16 12:14 28
c74066db Poul Sander 2022-02-16 12:14 29
// std::string is expected input
c74066db Poul Sander 2022-02-16 12:14 30
void run_test(const std::string& input) {
c74066db Poul Sander 2022-02-16 12:14 31
	test_internal(input);
c74066db Poul Sander 2022-02-16 12:14 32
}
c74066db Poul Sander 2022-02-16 12:14 33
c74066db Poul Sander 2022-02-16 12:14 34
// A special overload for the two funcs that take a vector
c74066db Poul Sander 2022-02-16 12:14 35
void run_test(const std::vector<std::string>& vec) {
c74066db Poul Sander 2022-02-16 12:14 36
	// Check each value for validity
c74066db Poul Sander 2022-02-16 12:14 37
	for (const std::string& elem : vec) {
c74066db Poul Sander 2022-02-16 12:14 38
		test_internal(elem);
c74066db Poul Sander 2022-02-16 12:14 39
	}
c74066db Poul Sander 2022-02-16 12:14 40
}
1970-01-01 00:00 41