feat(lib): initialize libnextcloud C++17 library scaffolding (#25)
This commit is contained in:
140
shared/tests/smoke_test.cpp
Normal file
140
shared/tests/smoke_test.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <nextcloud/version.hpp>
|
||||
#include <nextcloud/types.hpp>
|
||||
|
||||
/**
|
||||
* @file smoke_test.cpp
|
||||
* @brief Basic smoke tests to verify library setup
|
||||
*
|
||||
* These tests ensure that the library headers compile correctly
|
||||
* and basic functionality works as expected.
|
||||
*/
|
||||
|
||||
namespace {
|
||||
|
||||
// Test version information
|
||||
TEST(VersionTest, VersionConstants) {
|
||||
EXPECT_EQ(nextcloud::VERSION_MAJOR, 0);
|
||||
EXPECT_EQ(nextcloud::VERSION_MINOR, 1);
|
||||
EXPECT_EQ(nextcloud::VERSION_PATCH, 0);
|
||||
EXPECT_STREQ(nextcloud::VERSION_STRING, "0.1.0");
|
||||
}
|
||||
|
||||
TEST(VersionTest, GetVersionString) {
|
||||
std::string version = nextcloud::getVersionString();
|
||||
EXPECT_EQ(version, "0.1.0");
|
||||
}
|
||||
|
||||
TEST(VersionTest, GetVersionComponents) {
|
||||
int major, minor, patch;
|
||||
nextcloud::getVersion(major, minor, patch);
|
||||
EXPECT_EQ(major, 0);
|
||||
EXPECT_EQ(minor, 1);
|
||||
EXPECT_EQ(patch, 0);
|
||||
}
|
||||
|
||||
TEST(VersionTest, IsVersionAtLeast) {
|
||||
// Current version is 0.1.0
|
||||
EXPECT_TRUE(nextcloud::isVersionAtLeast(0, 0, 0));
|
||||
EXPECT_TRUE(nextcloud::isVersionAtLeast(0, 1, 0));
|
||||
EXPECT_FALSE(nextcloud::isVersionAtLeast(0, 2, 0));
|
||||
EXPECT_FALSE(nextcloud::isVersionAtLeast(1, 0, 0));
|
||||
}
|
||||
|
||||
// Test error types
|
||||
TEST(TypesTest, ErrorToString) {
|
||||
EXPECT_STREQ(nextcloud::errorToString(nextcloud::NextcloudError::Success), "Success");
|
||||
EXPECT_STREQ(nextcloud::errorToString(nextcloud::NextcloudError::NetworkError), "Network error");
|
||||
EXPECT_STREQ(nextcloud::errorToString(nextcloud::NextcloudError::AuthenticationFailed), "Authentication failed");
|
||||
EXPECT_STREQ(nextcloud::errorToString(nextcloud::NextcloudError::FileNotFound), "File not found");
|
||||
}
|
||||
|
||||
TEST(TypesTest, ResultSuccess) {
|
||||
nextcloud::Result<int> result;
|
||||
result.error = nextcloud::NextcloudError::Success;
|
||||
result.value = 42;
|
||||
|
||||
EXPECT_TRUE(result.isSuccess());
|
||||
EXPECT_FALSE(result.isError());
|
||||
EXPECT_EQ(result.value, 42);
|
||||
}
|
||||
|
||||
TEST(TypesTest, ResultError) {
|
||||
nextcloud::Result<std::string> result;
|
||||
result.error = nextcloud::NextcloudError::NetworkError;
|
||||
result.value = "";
|
||||
|
||||
EXPECT_FALSE(result.isSuccess());
|
||||
EXPECT_TRUE(result.isError());
|
||||
EXPECT_STREQ(result.errorMessage(), "Network error");
|
||||
}
|
||||
|
||||
TEST(TypesTest, UploadProgressStruct) {
|
||||
nextcloud::UploadProgress progress;
|
||||
progress.filename = "test.txt";
|
||||
progress.bytesUploaded = 50;
|
||||
progress.totalBytes = 100;
|
||||
progress.percentComplete = 50.0f;
|
||||
progress.bytesPerSecond = 1024.0f;
|
||||
progress.secondsRemaining = 1;
|
||||
|
||||
EXPECT_EQ(progress.filename, "test.txt");
|
||||
EXPECT_EQ(progress.bytesUploaded, 50);
|
||||
EXPECT_EQ(progress.totalBytes, 100);
|
||||
EXPECT_FLOAT_EQ(progress.percentComplete, 50.0f);
|
||||
}
|
||||
|
||||
TEST(TypesTest, FileInfoStruct) {
|
||||
nextcloud::FileInfo file;
|
||||
file.name = "document.pdf";
|
||||
file.path = "/Documents/document.pdf";
|
||||
file.isDirectory = false;
|
||||
file.size = 1024;
|
||||
file.modifiedTime = 1234567890;
|
||||
file.contentType = "application/pdf";
|
||||
|
||||
EXPECT_EQ(file.name, "document.pdf");
|
||||
EXPECT_EQ(file.path, "/Documents/document.pdf");
|
||||
EXPECT_FALSE(file.isDirectory);
|
||||
EXPECT_EQ(file.size, 1024);
|
||||
}
|
||||
|
||||
TEST(TypesTest, FolderInfoStruct) {
|
||||
nextcloud::FolderInfo folder;
|
||||
folder.path = "/Photos";
|
||||
folder.displayName = "My Photos";
|
||||
folder.lastUsed = 1234567890;
|
||||
folder.isFavorite = true;
|
||||
|
||||
EXPECT_EQ(folder.path, "/Photos");
|
||||
EXPECT_EQ(folder.displayName, "My Photos");
|
||||
EXPECT_TRUE(folder.isFavorite);
|
||||
}
|
||||
|
||||
TEST(TypesTest, HttpResponseSuccess) {
|
||||
nextcloud::HttpResponse response;
|
||||
response.statusCode = 200;
|
||||
response.body = "OK";
|
||||
response.contentType = "text/plain";
|
||||
response.error = nextcloud::NextcloudError::Success;
|
||||
|
||||
EXPECT_TRUE(response.isSuccess());
|
||||
EXPECT_EQ(response.statusCode, 200);
|
||||
}
|
||||
|
||||
TEST(TypesTest, HttpResponseError) {
|
||||
nextcloud::HttpResponse response;
|
||||
response.statusCode = 404;
|
||||
response.body = "Not Found";
|
||||
response.error = nextcloud::NextcloudError::FileNotFound;
|
||||
|
||||
EXPECT_FALSE(response.isSuccess());
|
||||
EXPECT_EQ(response.statusCode, 404);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user