88 lines
3.8 KiB
C++
88 lines
3.8 KiB
C++
#ifdef WIN_UNIT_TEST
|
|
#include "CppUnitTest.h"
|
|
#include "../../cppjson/jsonobject.h"
|
|
#include "./component/permissions.h"
|
|
#include "./component/storagenode.h"
|
|
#include "./component/storagelocation.h"
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
namespace sequencelogicSamd
|
|
{
|
|
TEST_CLASS(StorageLocation)
|
|
{
|
|
public:
|
|
|
|
TEST_METHOD(UseStorageLocation)
|
|
{
|
|
// Test for default constructor
|
|
sequencelogic::StorageLocation loc1;
|
|
std::shared_ptr<sequencelogic::JSONObject> p1 = loc1.getAsJson();
|
|
Assert::IsNotNull(p1.get());
|
|
std::string empty_str("");
|
|
std::string loc_data1("{\"bucket_id\":\"\","
|
|
"\"kind\":\"fs\","
|
|
"\"status\":\"flushed\","
|
|
"\"type\":\"l1\"}");
|
|
Assert::AreEqual(p1->toString(), loc_data1);
|
|
|
|
// Indirectly tests toString() overloads
|
|
std::string bucket_id2 = "https://api.dropbox.com";
|
|
sequencelogic::StorageLocation loc2(sequencelogic::StorageLocation::LOCATE_TYPE::CS,
|
|
sequencelogic::StorageLocation::LOCATE_KIND::DROPBOX,
|
|
bucket_id2,
|
|
sequencelogic::StorageLocation::LOCATE_STATUS::OK);
|
|
std::shared_ptr<sequencelogic::JSONObject> p2 = loc2.getAsJson();
|
|
Assert::IsNotNull(p2.get());
|
|
std::string loc_data2("{\"bucket_id\":\"https://api.dropbox.com\","
|
|
"\"kind\":\"dropbox\","
|
|
"\"status\":\"ok\","
|
|
"\"type\":\"cs\"}");
|
|
Assert::AreEqual(p2->toString(), loc_data2);
|
|
|
|
// Indirectly tests StorageLocation::toLocKind(), ::toLocStatus(), and ::toLocType()
|
|
sequencelogic::JSONObject loc_data3(loc_data2);
|
|
sequencelogic::StorageLocation loc3(loc_data3);
|
|
Assert::AreEqual(loc3.getBucketId(), bucket_id2);
|
|
Assert::IsTrue(loc3.getKind() == sequencelogic::StorageLocation::LOCATE_KIND::DROPBOX);
|
|
Assert::IsTrue(loc3.getStatus() == sequencelogic::StorageLocation::LOCATE_STATUS::OK);
|
|
Assert::IsTrue(loc3.getType() == sequencelogic::StorageLocation::LOCATE_TYPE::CS);
|
|
|
|
// Create StorageLocation using ill-formed json
|
|
sequencelogic::JSONObject loc_data4;
|
|
sequencelogic::StorageLocation loc4(loc_data4);
|
|
Assert::AreEqual(empty_str, loc4.getBucketId());
|
|
Assert::IsTrue(loc4.getKind() == sequencelogic::StorageLocation::LOCATE_KIND::UNKNOWN);
|
|
Assert::IsTrue(loc4.getStatus() == sequencelogic::StorageLocation::LOCATE_STATUS::UNKNOWN);
|
|
Assert::IsTrue(loc4.getType() == sequencelogic::StorageLocation::LOCATE_TYPE::UNKNOWN);
|
|
}
|
|
};
|
|
TEST_CLASS(StorageNode) {
|
|
public:
|
|
|
|
TEST_METHOD(GetDefaultLocation) {
|
|
std::string node_data1("{\"name\":\"node1\","
|
|
"\"length\":\"1\","
|
|
"\"mount\":\"m\"}");
|
|
sequencelogic::StorageNode node1(node_data1);
|
|
sequencelogic::StorageLocation loc1 = node1.getLocation();
|
|
Assert::IsTrue(loc1.getKind() == sequencelogic::StorageLocation::LOCATE_KIND::FS);
|
|
Assert::IsTrue(loc1.getStatus() == sequencelogic::StorageLocation::LOCATE_STATUS::FLUSHED);
|
|
Assert::IsTrue(loc1.getType() == sequencelogic::StorageLocation::LOCATE_TYPE::L1);
|
|
}
|
|
TEST_METHOD(GetDefaultRemoteLocation) {
|
|
std::string node_data1("{\"name\":\"node1\","
|
|
"\"length\":\"1\","
|
|
"\"mount\":\"m\"}");
|
|
sequencelogic::StorageNode node1(node_data1);
|
|
sequencelogic::StorageLocation remote_loc1 = node1.getRemoteLocation();
|
|
Assert::IsTrue(remote_loc1.getKind() == sequencelogic::StorageLocation::LOCATE_KIND::UNKNOWN);
|
|
Assert::IsTrue(remote_loc1.getStatus() == sequencelogic::StorageLocation::LOCATE_STATUS::FLUSHED);
|
|
Assert::IsTrue(remote_loc1.getType() == sequencelogic::StorageLocation::LOCATE_TYPE::UNKNOWN);
|
|
}
|
|
|
|
};
|
|
}
|
|
#endif
|