summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-15 20:56:26 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-15 20:56:26 -0500
commitf3ac764684c64fbdd2094853a80b23e570cd5d9c (patch)
tree3b7f64480a1247455d28e23b6bb5ff63303c9170 /test
parent71976e927cca43b970cb659c03fd6908c352ea3d (diff)
Conver to using static constructors for string, sqlite, files.
Diffstat (limited to 'test')
-rw-r--r--test/test_directory.cpp25
-rw-r--r--test/test_sqlite.cpp21
-rw-r--r--test/test_string.cpp19
3 files changed, 40 insertions, 25 deletions
diff --git a/test/test_directory.cpp b/test/test_directory.cpp
index ff10c2d..6597195 100644
--- a/test/test_directory.cpp
+++ b/test/test_directory.cpp
@@ -51,7 +51,7 @@ FudStatus removeRecursive(const String& path)
if (path.length() < 5) {
return FudStatus::InvalidInput;
}
- const String prefix{"/tmp/"};
+ auto prefix{String::makeFromCString("/tmp/").takeOkay()};
auto diffResult = compareMem(path.data(), path.length(), prefix.data(), prefix.length());
if (diffResult.isError()) {
return FudStatus::InvalidInput;
@@ -75,13 +75,12 @@ FudStatus removeRecursive(const String& path)
TEST(FudDirectory, Basic)
{
- const String testDirName{"/tmp/fud_directory_test"};
+ const auto testDirName{String::makeFromCString("/tmp/fud_directory_test").takeOkay()};
ASSERT_TRUE(testDirName.utf8Valid());
constexpr mode_t pathMode = 0777;
const Array<String, 2> files{
- String{"file1"},
- String{"file2"},
- };
+ String::makeFromCString("file1").takeOkay(),
+ String::makeFromCString("file2").takeOkay()};
ASSERT_TRUE(files[0].utf8Valid());
ASSERT_TRUE(files[1].utf8Valid());
@@ -94,12 +93,14 @@ TEST(FudDirectory, Basic)
return;
}
- const String testDirNamePrefix = testDirName.catenate("/");
+ const String testDirNamePrefix{testDirName.catenate("/").takeOkay()};
ASSERT_TRUE(testDirNamePrefix.utf8Valid());
for (const auto& fnameBase : files) {
- const auto fname = testDirNamePrefix.catenate(fnameBase);
+ const auto fname{testDirNamePrefix.catenate(fnameBase).takeOkay()};
ASSERT_TRUE(fname.utf8Valid());
- CBinaryFile file{fname, CFileMode::ReadWriteTruncate};
+ auto fileResult{CBinaryFile::make(fname, CFileMode::ReadWriteTruncate)};
+ ASSERT_TRUE(fileResult.isOkay());
+ CBinaryFile file{std::move(fileResult).takeOkay()};
ASSERT_EQ(file.open(), FudStatus::Success);
Array<utf8, 5> data{"test"};
WriteResult expected{data.size(), FudStatus::Success};
@@ -113,8 +114,8 @@ TEST(FudDirectory, Basic)
ASSERT_EQ(directory.errorCode(), 0);
const Array<DirectoryEntry, 4> expectedFiles{
- DirectoryEntry{String{"."}, 0, 0, 2, 0, DirectoryEntryType::Directory},
- DirectoryEntry{String{".."}, 0, 0, 1, 0, DirectoryEntryType::Directory},
+ DirectoryEntry{String::makeFromCString(".").takeOkay(), 0, 0, 2, 0, DirectoryEntryType::Directory},
+ DirectoryEntry{String::makeFromCString("..").takeOkay(), 0, 0, 1, 0, DirectoryEntryType::Directory},
DirectoryEntry{files[0], 0, files[0].size(), 1, 0, DirectoryEntryType::RegularFile},
DirectoryEntry{files[1], 0, files[1].size(), 1, 0, DirectoryEntryType::RegularFile},
};
@@ -131,7 +132,9 @@ TEST(FudDirectory, Basic)
const auto* expected = std::find_if(
expectedFiles.begin(),
expectedFiles.end(),
- [&dirEntry](const DirectoryEntry& entry) { return entry.name.compare(dirEntry.name) && entry.entryType == dirEntry.entryType; });
+ [&dirEntry](const DirectoryEntry& entry) {
+ return entry.name.compare(dirEntry.name) && entry.entryType == dirEntry.entryType;
+ });
EXPECT_NE(expected, nullptr);
EXPECT_NE(expected, expectedFiles.end());
}
diff --git a/test/test_sqlite.cpp b/test/test_sqlite.cpp
index 8349324..2bb91a0 100644
--- a/test/test_sqlite.cpp
+++ b/test/test_sqlite.cpp
@@ -17,7 +17,6 @@
#include "fud_sqlite.hpp"
#include "fud_string.hpp"
-#include "test_common.hpp"
#include "gtest/gtest.h"
#include <cerrno>
@@ -27,23 +26,27 @@ namespace fud {
TEST(FudSqlite, Basic)
{
- const String testName{"test.db.sqlite"};
+ auto testNameResult = String::makeFromCString("./test.db.sqlite");
+ ASSERT_TRUE(testNameResult.isOkay());
+ auto testName{std::move(testNameResult).takeOkay()};
auto result = unlink(testName.c_str());
if (result != 0) {
ASSERT_EQ(errno, ENOENT);
}
- SqliteDb sqliteDb{testName, SqliteOpenMode::ReadOnly};
- ASSERT_FALSE(sqliteDb.valid());
- ASSERT_NE(sqliteDb.errorCode(), SQLITE_OK);
+ auto sqliteDbResult{SqliteDb::make(testName, SqliteOpenMode::ReadOnly)};
+ ASSERT_FALSE(sqliteDbResult.isOkay());
- sqliteDb = SqliteDb{testName, SqliteOpenMode::ReadWrite};
- ASSERT_FALSE(sqliteDb.valid());
- ASSERT_NE(sqliteDb.errorCode(), SQLITE_OK);
+ sqliteDbResult = SqliteDb::make(testName, SqliteOpenMode::ReadWrite);
+ ASSERT_FALSE(sqliteDbResult.isOkay());
- sqliteDb = SqliteDb{testName, SqliteOpenMode::ReadWriteCreate};
+ sqliteDbResult = SqliteDb::make(testName, SqliteOpenMode::ReadWriteCreate);
+ ASSERT_TRUE(sqliteDbResult.isOkay());
+
+ auto sqliteDb{std::move(sqliteDbResult).takeOkay()};
ASSERT_TRUE(sqliteDb.valid());
ASSERT_EQ(sqliteDb.errorCode(), SQLITE_OK);
+
}
} // namespace fud
diff --git a/test/test_string.cpp b/test/test_string.cpp
index 15646bd..6d963c4 100644
--- a/test/test_string.cpp
+++ b/test/test_string.cpp
@@ -37,13 +37,20 @@ TEST(FudString, BasicStringOps)
const Array<utf8, 2> invalid{0xFF, 0x00};
ASSERT_FALSE(Ascii::valid(invalid[0]));
const Array<utf8, 2> invalid2{0xFF, 0x00};
- String fudString{invalid2.data()};
+
+ auto stringResult = String::makeFromCString(invalid2.data());
+ ASSERT_TRUE(stringResult.isOkay());
+
+ String fudString{stringResult.getOkay()};
ASSERT_EQ(fudString.length(), 1);
ASSERT_EQ(fudString.data()[0], invalid[0]);
ASSERT_FALSE(Ascii::valid(fudString.data()[0]));
ASSERT_FALSE(fudString.utf8Valid());
- fudString = String{"TEST"};
+ stringResult = String::makeFromCString("TEST");
+ ASSERT_TRUE(stringResult.isOkay());
+ fudString = stringResult.getOkay();
+
ASSERT_TRUE(fudString.utf8Valid());
StringView view1{};
@@ -56,7 +63,9 @@ TEST(FudString, BasicStringOps)
TEST(FudString, HeapAlloc)
{
constexpr const char filenameLiteral[] = "Amazing Saga Volume 01/000.jpg";
- String filename{filenameLiteral};
+ auto filenameResult{String::makeFromCString(filenameLiteral)};
+ ASSERT_TRUE(filenameResult.isOkay());
+ auto filename{filenameResult.getOkay()};
ASSERT_EQ(filename.length(), sizeof(filenameLiteral) - 1);
}
@@ -102,7 +111,7 @@ TEST(TestFudString, StringBuffer)
Array<uint8_t, 1> data1{};
bufferResult = FixedStringBuffer<1>::fromArray(data1);
ASSERT_TRUE(bufferResult.isOkay());
- FixedStringBuffer<1> buffer1{std::move(bufferResult.getOkay())};
+ FixedStringBuffer<1> buffer1{std::move(bufferResult).getOkay()};
ASSERT_EQ(buffer1.m_string.m_data[0], '\0');
ASSERT_EQ(buffer1.m_string.m_length, 0);
ASSERT_EQ(buffer1.m_string.m_size, 1);
@@ -137,7 +146,7 @@ TEST(TestFudString, StringBuffer)
Array<uint8_t, sizeof("test")> data2{"test"};
auto bufferResult2{FixedStringBuffer<data2.size()>::fromArray(data2)};
ASSERT_TRUE(bufferResult2.isOkay());
- FixedStringBuffer<data2.size()> bufferTest{std::move(bufferResult2.getOkay())};
+ FixedStringBuffer<data2.size()> bufferTest{std::move(bufferResult2).getOkay()};
ASSERT_EQ(bufferTest.m_string.m_data[0], 't');
ASSERT_EQ(bufferTest.m_string.m_data[4], '\0');
ASSERT_EQ(bufferTest.m_string.m_length, data2.size() - 1);