summaryrefslogtreecommitdiffhomepage
path: root/FoundationEx/test
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-03-18 23:41:20 +0100
committerAki <please@ignore.pl>2024-03-18 23:41:20 +0100
commit2066e4911948d11cac5a234d2f7773dc5f06ba96 (patch)
tree27c7672aad884d1307736b3d15e704d7d786b314 /FoundationEx/test
parent3df6ccddcbd881c2474746f5f1758b095c866a67 (diff)
downloadstarshatter-2066e4911948d11cac5a234d2f7773dc5f06ba96.zip
starshatter-2066e4911948d11cac5a234d2f7773dc5f06ba96.tar.gz
starshatter-2066e4911948d11cac5a234d2f7773dc5f06ba96.tar.bz2
Added filesystem-only starshatter::data DataLoader replacement
Step by step. The intent is to find a good spot between current data representations and the standard library and put the intermediate stage there. After it matures a bit, we can move further away.
Diffstat (limited to 'FoundationEx/test')
-rw-r--r--FoundationEx/test/data.cpp26
-rw-r--r--FoundationEx/test/reader.cpp13
2 files changed, 32 insertions, 7 deletions
diff --git a/FoundationEx/test/data.cpp b/FoundationEx/test/data.cpp
new file mode 100644
index 0000000..09ab49b
--- /dev/null
+++ b/FoundationEx/test/data.cpp
@@ -0,0 +1,26 @@
+#include <filesystem>
+#include <fstream>
+
+#include <gtest/gtest.h>
+
+#include <starshatter/foundation/data.h>
+
+
+namespace data = starshatter::foundation::data;
+namespace fs = std::filesystem;
+
+
+TEST(FoundationEx, OpenRelativePathOnFilesystem)
+{
+ fs::current_path(fs::temp_directory_path());
+ {
+ std::fstream tmp("sample", tmp.out | tmp.binary);
+ tmp << "Hello, there!\n";
+ }
+ data::toggle_filesystem(true);
+ auto file = data::open("sample");
+ ASSERT_TRUE(file.valid());
+ ASSERT_LT(0, file.available());
+ const auto text = file.more();
+ ASSERT_STREQ("Hello, there!\n", text);
+}
diff --git a/FoundationEx/test/reader.cpp b/FoundationEx/test/reader.cpp
index 395ad81..4bc4882 100644
--- a/FoundationEx/test/reader.cpp
+++ b/FoundationEx/test/reader.cpp
@@ -17,7 +17,8 @@ TEST(FoundationEx, ReadFromView)
{
Reader reader("Hello, World!");
ASSERT_TRUE(reader.valid());
- std::vector<char> buffer(reader.available());
+ const auto s = reader.available();
+ std::vector<char> buffer(s);
ASSERT_EQ(14, buffer.size());
const auto bytes = reader.read(buffer.data());
ASSERT_EQ(14, bytes);
@@ -54,12 +55,10 @@ TEST(FoundationEx, RelativeSeek)
TEST(FoundationEx, CreateTextFromReader)
{
const char* ref = "Hello!";
- const auto size = 7;
- auto ptr = std::make_unique<char[]>(size);
- for (auto i = 0; i < size; ++i)
- ptr[i] = ref[i];
+ auto ptr = std::make_unique<char[]>(std::strlen(ref) + 1);
+ std::strcpy(ptr.get(), ref);
Reader reader(std::move(ptr));
ASSERT_TRUE(reader.valid());
- Text text(reader.data());
- ASSERT_EQ("Hello!", text);
+ const auto text = reader.more();
+ ASSERT_STREQ(ref, text);
}