mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
refactor: make filenames consistent
Use cpp header files
This commit is contained in:
parent
6df34b5529
commit
6ace621748
@ -9,17 +9,17 @@ project(
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
add_subdirectory(Cppunit)
|
||||
add_subdirectory(Prep)
|
||||
add_subdirectory(cppunit)
|
||||
add_subdirectory(prep)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
add_library(mainLib main_lib.cpp main_lib.h)
|
||||
target_link_libraries(main PUBLIC mainLib)
|
||||
target_link_libraries(mainLib PUBLIC prepLib)
|
||||
add_library(lib lib.cpp lib.hh)
|
||||
target_link_libraries(main PUBLIC lib)
|
||||
target_link_libraries(lib PUBLIC prepLib)
|
||||
target_include_directories(main PUBLIC "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/Prep")
|
||||
target_include_directories(mainLib PUBLIC "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/Prep")
|
||||
"${PROJECT_SOURCE_DIR}/prep")
|
||||
target_include_directories(lib PUBLIC "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/prep")
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
@ -29,7 +29,7 @@ FetchContent_Declare(
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
add_executable(runtests test.cpp)
|
||||
target_link_libraries(runtests PUBLIC mainLib gtest gtest_main)
|
||||
target_link_libraries(runtests PUBLIC lib gtest gtest_main)
|
||||
target_include_directories(runtests PUBLIC "${PROJECT_BINARY_DIR}")
|
||||
|
||||
include(GoogleTest)
|
||||
|
||||
@ -1 +0,0 @@
|
||||
add_library(cppunit cppunit.cpp cppunit.h)
|
||||
@ -1 +0,0 @@
|
||||
add_library(prepLib Prep.cpp Prep.h)
|
||||
@ -1,3 +0,0 @@
|
||||
#include "Prep.h"
|
||||
|
||||
int add(int a, int b) { return a + b; }
|
||||
1
src/cppunit/CMakeLists.txt
Normal file
1
src/cppunit/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_library(cppunit cppunit.cpp cppunit.hh)
|
||||
@ -11,33 +11,33 @@
|
||||
|
||||
// CPlusPlusUnit - C++ Unit testing TDD framework (github.com/cppunit/cppunit)
|
||||
class Cppunit {
|
||||
public:
|
||||
#define CHECK(a, b) \
|
||||
check<long long>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
||||
#define CHECKT(a) \
|
||||
check<bool>(a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
|
||||
public:
|
||||
#define CHECK(a, b) check<long long>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
||||
#define CHECKT(a) check<bool>(a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
|
||||
#define CHECKS(a, b) check<cs>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
||||
typedef const std::string &cs;
|
||||
int checks, fails;
|
||||
std::ostringstream serr;
|
||||
std::istringstream *in;
|
||||
Cppunit() { checks = fails = 0; }
|
||||
|
||||
Cppunit() {
|
||||
checks = fails = 0;
|
||||
}
|
||||
|
||||
void test_cin(cs s) {
|
||||
in = new std::istringstream(s);
|
||||
std::cin.rdbuf(in->rdbuf());
|
||||
}
|
||||
|
||||
void fail_hdr(cs stra, cs strb, cs file, int line, cs func) {
|
||||
serr << "=================================================="
|
||||
<< std::endl;
|
||||
serr << "==================================================" << std::endl;
|
||||
serr << "FAIL: " << func << std::endl;
|
||||
serr << "--------------------------------------------------"
|
||||
<< std::endl;
|
||||
serr << "File \"" << file << "\", line " << line << " in " << func
|
||||
<< std::endl;
|
||||
serr << "--------------------------------------------------" << std::endl;
|
||||
serr << "File \"" << file << "\", line " << line << " in " << func << std::endl;
|
||||
serr << " Checking " << stra << " == " << strb << std::endl;
|
||||
}
|
||||
template <typename T>
|
||||
void check(T a, T b, cs stra, cs strb, cs file, int line, cs func) {
|
||||
|
||||
template <typename T> void check(T a, T b, cs stra, cs strb, cs file, int line, cs func) {
|
||||
checks++;
|
||||
if (a == b) {
|
||||
std::cout << ".";
|
||||
@ -46,27 +46,32 @@ class Cppunit {
|
||||
fails++;
|
||||
std::cout << "F";
|
||||
fail_hdr(stra, strb, file, line, func);
|
||||
serr << " Error: \"" << a << "\" ! = \"" << b << "\"" << std::endl
|
||||
<< std::endl;
|
||||
serr << " Error: \"" << a << "\" ! = \"" << b << "\"" << std::endl << std::endl;
|
||||
}
|
||||
virtual void single_test() {}
|
||||
virtual void test_list() { single_test(); }
|
||||
double dclock() { return double(clock()) / CLOCKS_PER_SEC; }
|
||||
|
||||
virtual void single_test() {
|
||||
}
|
||||
|
||||
virtual void test_list() {
|
||||
single_test();
|
||||
}
|
||||
|
||||
double dclock() {
|
||||
return double(clock()) / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
int status() {
|
||||
std::cout << std::endl;
|
||||
if (fails)
|
||||
std::cout << serr.str();
|
||||
std::cout << "--------------------------------------------------"
|
||||
<< std::endl;
|
||||
std::cout << "Ran " << checks << " checks in " << dclock() << "s"
|
||||
<< std::endl
|
||||
<< std::endl;
|
||||
if (fails) std::cout << serr.str();
|
||||
std::cout << "--------------------------------------------------" << std::endl;
|
||||
std::cout << "Ran " << checks << " checks in " << dclock() << "s" << std::endl << std::endl;
|
||||
if (fails)
|
||||
std::cout << "FAILED (failures=" << fails << ")";
|
||||
else
|
||||
std::cout << "OK" << std::endl;
|
||||
return fails > 0;
|
||||
}
|
||||
|
||||
int run() {
|
||||
std::streambuf *ocin = std::cin.rdbuf();
|
||||
test_list();
|
||||
@ -75,4 +80,4 @@ class Cppunit {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CPPUNIT_H
|
||||
#endif // CPPUNIT_H
|
||||
13
src/lib.cpp
Normal file
13
src/lib.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "lib.hh"
|
||||
|
||||
#include "prep/prep.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void run() {
|
||||
std::cout << add(2, 2) << std::endl;
|
||||
}
|
||||
|
||||
int functionToTest(int a) {
|
||||
return a * 2;
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
#include "main_lib.h"
|
||||
#include "lib.hh"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
#include "main_lib.h"
|
||||
#include "Prep.h"
|
||||
#include <iostream>
|
||||
|
||||
void run() { std::cout << add(2, 2) << std::endl; }
|
||||
|
||||
int functionToTest(int a) { return a * 2; }
|
||||
1
src/prep/CMakeLists.txt
Normal file
1
src/prep/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_library(prepLib prep.cpp prep.hh)
|
||||
5
src/prep/prep.cpp
Normal file
5
src/prep/prep.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "prep.hh"
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
@ -10,10 +10,34 @@
|
||||
int add(int a, int b);
|
||||
|
||||
// All IDs are uint32_t
|
||||
enum EventType { PHASE_CHANGE, ACTION, ROOM_STATE_CHANGE, PLAYER_STATE_CHANGE };
|
||||
enum Action { KILL, VOTE, INVESTIGATE, HEAL, PROTECT };
|
||||
enum RoomStatus { AWAITING_START, IN_PROGRESS, STOPPED, ENDED };
|
||||
enum PlayerStatus { KICKED, ALIVE, DEAD, VOTED_OUT };
|
||||
enum EventType {
|
||||
PHASE_CHANGE,
|
||||
ACTION,
|
||||
ROOM_STATE_CHANGE,
|
||||
PLAYER_STATE_CHANGE,
|
||||
};
|
||||
|
||||
enum Action {
|
||||
KILL,
|
||||
VOTE,
|
||||
INVESTIGATE,
|
||||
HEAL,
|
||||
PROTECT,
|
||||
};
|
||||
|
||||
enum RoomStatus {
|
||||
AWAITING_START,
|
||||
IN_PROGRESS,
|
||||
STOPPED,
|
||||
ENDED,
|
||||
};
|
||||
|
||||
enum PlayerStatus {
|
||||
KICKED,
|
||||
ALIVE,
|
||||
DEAD,
|
||||
VOTED_OUT,
|
||||
};
|
||||
|
||||
struct Role;
|
||||
struct Player;
|
||||
18
src/test.cpp
18
src/test.cpp
@ -1,9 +1,17 @@
|
||||
#include "Prep.h"
|
||||
#include "main_lib.h"
|
||||
#include "lib.hh"
|
||||
#include "prep/prep.hh"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// TEST(TestSuiteName, testName) {...}
|
||||
TEST(ProgramTest, testFunction) { EXPECT_EQ(functionToTest(4), 8); }
|
||||
TEST(ProgramTest, testFunctionShouldFail) { EXPECT_EQ(functionToTest(4), 12); }
|
||||
TEST(ProgramTest, testFunction) {
|
||||
EXPECT_EQ(functionToTest(4), 8);
|
||||
}
|
||||
|
||||
TEST(PrepTest, testAddFunc) { EXPECT_EQ(add(4, 2), 6); }
|
||||
TEST(ProgramTest, testFunctionShouldFail) {
|
||||
EXPECT_EQ(functionToTest(4), 12);
|
||||
}
|
||||
|
||||
TEST(PrepTest, testAddFunc) {
|
||||
EXPECT_EQ(add(4, 2), 6);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user