Skip to content

Commit

Permalink
First set of attribute tests. Contains one case of a value being copi…
Browse files Browse the repository at this point in the history
…ed over and one case of a value being changed from zero to false.
  • Loading branch information
klingbolt committed Oct 9, 2023
1 parent 850a180 commit a3329fa
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
8 changes: 8 additions & 0 deletions xml_converter/test_cases/can_fade_tests/can_fade_is_false.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<OverlayData>
<MarkerCategory Name="IsFalse">
</MarkerCategory>

<POIs>
<POI CanFade="false"/>
</POIs>
</OverlayData>
8 changes: 8 additions & 0 deletions xml_converter/test_cases/can_fade_tests/can_fade_is_zero.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<OverlayData>
<MarkerCategory Name="IsZero">
</MarkerCategory>

<POIs>
<POI CanFade="0" Type="IsZero"/>
</POIs>
</OverlayData>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<OverlayData>
<MarkerCategory Name="IsZero">
</MarkerCategory>

<POIs>
<POI CanFade="false" Type="IsZero"/>
</POIs>
</OverlayData>
8 changes: 8 additions & 0 deletions xml_converter/test_cases/test_output/can_fade_is_false.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<OverlayData>
<MarkerCategory Name="IsFalse">
</MarkerCategory>

<POIs>
<POI CanFade="false"/>
</POIs>
</OverlayData>
70 changes: 70 additions & 0 deletions xml_converter/tests/test_bool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "../src/attribute/bool.hpp"
#include "../src/packaging_xml.hpp"
#include <gtest/gtest.h>
#include <fstream>

class BoolTest : public ::testing::Test {
protected:
void SetUp() override {
}
void TearDown() override {
}
};

bool compare_files(const std::string& file1_path, const std::string& file2_path) {
std::ifstream file1(file1_path);
std::ifstream file2(file2_path);

if (!file1.is_open() || !file2.is_open()) {
std::cerr << "Error: Could not open one or both of the files." << std::endl;
return false;
}

char char1, char2;
bool files_are_equal = true;

while (true) {
char1 = file1.get();
char2 = file2.get();

if (char1 != char2) {
files_are_equal = false;
break;
}

if (file1.eof() && file2.eof()) {
break; // Reached the end of both files
}

// If one file reaches the end before the other, they are not equal
if (file1.eof() || file2.eof()) {
files_are_equal = false;
break;
}
}

file1.close();
file2.close();

return files_are_equal;
}

TEST_F(BoolTest, ValueIsFalse) {
std::map<std::string, Category> marker_categories;
std::vector<Parseable*> parsed_pois;
std::string xml_input = "../test_cases/can_fade_tests/can_fade_is_false.xml";
std::string xml_output = "../test_cases/test_output/can_fade_is_false.xml";
parse_xml_file(xml_input, &marker_categories, &parsed_pois);
write_xml_file(xml_output, &marker_categories, &parsed_pois);
EXPECT_TRUE(compare_files(xml_input, xml_output));
}

TEST_F(BoolTest, ValueIsZero) {
std::map<std::string, Category> marker_categories;
std::vector<Parseable*> parsed_pois;
std::string xml_input = "../test_cases/can_fade_tests/can_fade_is_zero.xml";
std::string xml_output = "../test_cases/test_output/can_fade_corrected_zero.xml";
parse_xml_file(xml_input, &marker_categories, &parsed_pois);
write_xml_file(xml_output, &marker_categories, &parsed_pois);
EXPECT_FALSE(compare_files(xml_input, xml_output));
}

0 comments on commit a3329fa

Please sign in to comment.