123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #include <array>
- #include <map>
- #include <string>
- #include <vector>
- #include "director.h"
- #include "galaxy.h"
- #include "gtest/gtest.h"
- #include "utils.h"
- /*
- How can I add logging, but not really add/use it?
- */
- #define GTEST_COUT std::cerr << "[ ] [ INFO ]"
- namespace {
- TEST(director, director_debugging) {
- Director dir;
- std::vector<std::string> client;
- std::vector<std::string> server;
- dir.to_client = [&client](const std::string line) -> void { client.push_back(line); };
- dir.to_server = [&server](const std::string &line, const std::string &source) -> void { server.push_back(line); };
- // dir.to_server = [](const std::string &line, const std::string &source) -> void { server.push_back(line); };
- // activating the game gets this over to dir.galaxy.username.
- dir.username = "test";
- // should I setup galaxy-N-test.yaml ? Probably yes.
- std::string lines[] = {
- "TradeWars Game Server Copyright (C) "
- "EIS",
- "Selection (? for menu): N",
- "Trade Wars 2002 Win32 module now loading.",
- " ==-- Trade Wars 2002 --==",
- "Enter your choice: ",
- "^Command [TL=00:00:00]:[2985] (?=Help)? :"};
- for (auto line : lines) {
- if (line[0] == '^') {
- dir.server_prompt(line.substr(1), line.substr(1));
- } else if (line[0] == '!') {
- // client input
- dir.client_input(line.substr(1));
- } else {
- dir.server_line(line, line);
- }
- }
- EXPECT_EQ(client[0],
- "\rTradeWars Proxy v2++ READY (~ or ESC to activate)\n\r");
- client.clear();
- dir.client_input("~");
- for (auto line : client) {
- GTEST_COUT << line << std::endl;
- }
- }
- /* // my save rountine handles sequences. This is a NOP.
- TEST(director, director_galaxy_save) {
- Director dir;
- dir.galaxy.username = "test";
- dir.galaxy.game = 'Z';
- // This causes a YAML::Node Sequence
- dir.galaxy.meta["trade"][10963][0] = 1;
- dir.galaxy.save();
- EXPECT_TRUE(1) << "No exception, this is good!";
- }
- */
- TEST(director, director_parsing_density) {
- Director dir;
- std::vector<std::string> client;
- std::vector<std::string> server;
- dir.to_client = [&client](const std::string line) { client.push_back(line); };
- dir.to_server = [&server](const std::string &line, const std::string &source) { server.push_back(line); };
- dir.username = "test";
- std::string lines[] = {
- "TradeWars Game Server Copyright (C) "
- "EIS",
- "Selection (? for menu): N",
- "^Command [TL=00:00:00]:[2985] (?=Help)? :",
- "!s",
- "Command [TL=00:00:00]:[926] (?=Help)? : S",
- "",
- "Long Range Scan",
- "^Select (H)olo Scan or (D)ensity Scan or (Q)uit? [D] ",
- "!d",
- "Select (H)olo Scan or (D)ensity Scan or (Q)uit? [D] D",
- "",
- " Relative Density Scan",
- "------------------------------------------------------------------------"
- "-----",
- "Sector 70 ==> 0 Warps : 6 NavHaz : 0% Anom "
- ": No",
- "Sector 441 ==> 100 Warps : 2 NavHaz : 0% Anom "
- ": No",
- "Sector ( 575) ==> 1000 Warps : 2 NavHaz : 15% Anom "
- ": Yes",
- "Sector 600 ==> 40 Warps : 6 NavHaz : 0% Anom "
- ": No",
- "Sector 629 ==> 1 Warps : 4 NavHaz : 0% Anom "
- ": No",
- "Sector 711 ==> 101 Warps : 6 NavHaz : 0% Anom "
- ": No",
- ""};
- for (auto line : lines) {
- if (line[0] == '^') {
- dir.server_prompt(line.substr(1), line.substr(1));
- } else if (line[0] == '!') {
- // client input
- dir.client_input(line.substr(1));
- } else {
- dir.server_line(line, line);
- }
- }
- std::array<density, 6> dense = {{{70, 0, 6, 0, false, true},
- {441, 100, 2, 0, false, true},
- {575, 1000, 2, 15, true, false},
- {600, 40, 6, 0, false, true},
- {629, 1, 4, 0, false, true},
- {711, 101, 6, 0, false, true}}};
- for (auto const& s : dense) {
- auto d = dir.galaxy.dscan.find(s.sector);
- EXPECT_EQ(d, s) << "Sector " << s.sector << " density";
- }
- // Check that each sector was correctly processed
- std::vector<int> sectors = {70, 441, 575, 600, 629, 711};
- json sector_data;
- sector_data[70]["density"] = 0;
- sector_data[70]["warps"] = 6;
- sector_data[70]["navhaz"] = 0;
- sector_data[70]["anom"] = false;
- sector_data[70]["known"] = true;
- sector_data[441]["density"] = 100;
- sector_data[441]["warps"] = 2;
- sector_data[441]["navhaz"] = 0;
- sector_data[441]["anom"] = false;
- sector_data[441]["known"] = true;
- sector_data[575]["density"] = 1000;
- sector_data[575]["warps"] = 2;
- sector_data[575]["navhaz"] = 15;
- sector_data[575]["anom"] = true;
- sector_data[575]["known"] = false;
- sector_data[600]["density"] = 40;
- sector_data[600]["warps"] = 6;
- sector_data[600]["navhaz"] = 0;
- sector_data[600]["anom"] = false;
- sector_data[600]["known"] = true;
- sector_data[629]["density"] = 1;
- sector_data[629]["warps"] = 4;
- sector_data[629]["navhaz"] = 0;
- sector_data[629]["anom"] = false;
- sector_data[629]["known"] = true;
- sector_data[711]["density"] = 101;
- sector_data[711]["warps"] = 6;
- sector_data[711]["navhaz"] = 0;
- sector_data[711]["anom"] = false;
- sector_data[711]["known"] = true;
- density_scan &ds = dir.galaxy.dscan;
- for (int x = 0; x < ds.pos; ++x) {
- int sector = sectors[x];
- // GTEST_COUT << "Testing Sector " << sector << std::endl;
- EXPECT_EQ(ds.d[x].density,
- json_int(sector_data[sector]["density"]))
- << "Sector " << sector << " density";
- EXPECT_EQ(ds.d[x].warps,
- json_int(sector_data[sector]["warps"]))
- << "Sector " << sector << " warps";
- EXPECT_EQ(ds.d[x].navhaz,
- json_int(sector_data[sector]["navhaz"]))
- << "Sector " << sector << " navhaz";
- EXPECT_EQ(ds.d[x].anomaly,
- json_bool(sector_data[sector]["anom"]))
- << "Sector " << sector << " anom";
- EXPECT_EQ(ds.d[x].known,
- json_bool(sector_data[sector]["known"]))
- << "Sector " << sector << " known";
- }
- }
- } // namespace
|