Skip to content

Commit

Permalink
ISSUE #391 Removing print outs from st/ut and related functios from t…
Browse files Browse the repository at this point in the history
…est utils
  • Loading branch information
haroon-haider committed Dec 1, 2020
1 parent 5607d6d commit 6f5db15
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 191 deletions.
53 changes: 26 additions & 27 deletions test/src/system/st_3drepobouncerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ static int runProcess(
#endif
}


static int testUpload (
std::string mongoDbName,
std::string projectName,
std::string fileName
)
{
std::string bimUpload = produceUploadArgs(
mongoDbName,
projectName,
getDataPath(fileName));

int errCode = runProcess(bimUpload);
;
repoInfo << "Error code from bouncer client: " << errCode
<< ", " << (int)errCode;
return errCode;
};


TEST(RepoClientTest, UploadTestInvalidDBConn)
{
//this ensures we can run processes
Expand All @@ -134,6 +154,7 @@ TEST(RepoClientTest, UploadTestInvalidDBConn)
EXPECT_EQ((int)REPOERR_AUTH_FAILED, runProcess(failToConnect));
EXPECT_FALSE(projectExists(db, "failConn"));
}

TEST(RepoClientTest, UploadTestBadDBAuth)
{
//this ensures we can run processes
Expand Down Expand Up @@ -241,54 +262,32 @@ TEST(RepoClientTest, UploadTestMissingNodes)

TEST(RepoClientTest, UploadTestBIM)
{
repo::test::TestLogging::printTestTitleString(
"BIM format system tests",
"Confirming the correct response from bouncer client for BIM files");

////this ensures we can run processes
ASSERT_TRUE(system(nullptr));

auto testUpload = [](
std::string mongoDbName,
std::string projectName,
std::string fileName
)-> int
{
std::string bimUpload = produceUploadArgs(
mongoDbName,
projectName,
getDataPath(fileName));

int errCode = runProcess(bimUpload);
;
repoInfo << "Error code from bouncer client: " << errCode
<< ", " << repo::test::TestLogging::getStringFromRepoErrorCode(errCode);
return errCode;
};

std::string mongoDbName = "stUpload";

repo::test::TestLogging::printSubTestTitleString("OK BIM003 file with textures");
//OK BIM003 file with textures
std::string okBim3PrjName = "okBIM3Test";
EXPECT_EQ(REPOERR_OK, testUpload(mongoDbName, okBim3PrjName, "RepoModelImport/BrickWalls_bim3.bim"));
EXPECT_TRUE(projectExists(mongoDbName, okBim3PrjName));

repo::test::TestLogging::printSubTestTitleString("OK BIM002 file with no textures");
// OK BIM002 file with no textures
std::string okBim2PrjName = "okBIM2Test";
EXPECT_EQ(REPOERR_OK, testUpload(mongoDbName, okBim2PrjName, "RepoModelImport/cube_bim2_navis_2021_repo_4.6.1.bim"));
EXPECT_TRUE(projectExists(mongoDbName, okBim2PrjName));

repo::test::TestLogging::printSubTestTitleString("Spoofed BIM001");
// Spoofed BIM001
std::string spoofedBim1PrjName = "spoofedBIM1Test";
EXPECT_EQ(REPOERR_UNSUPPORTED_BIM_VERSION, testUpload(mongoDbName, spoofedBim1PrjName, "RepoModelImport/cube_bim1_spoofed.bim"));
EXPECT_FALSE(projectExists(mongoDbName, spoofedBim1PrjName));

repo::test::TestLogging::printSubTestTitleString("Corrupt BIM003 - Missing \"numImageBytes\" field");
// Corrupt BIM003 - Missing numImageBytes field
std::string corrTxtrBim3PrjName = "corruptedTextureBIM3Test";
EXPECT_EQ(REPOERR_LOAD_SCENE_MISSING_TEXTURE, testUpload(mongoDbName, corrTxtrBim3PrjName, "RepoModelImport/BrickWalls_bim3_CorruptedTextureField.bim"));
EXPECT_TRUE(projectExists(mongoDbName, corrTxtrBim3PrjName));

repo::test::TestLogging::printSubTestTitleString("Corrupt BIM003 - Material references a texture id not included in file");
// Corrupt BIM003 - Material references a texture id not included in file
std::string corrMatBim3PrjName = "corruptedMaterialBIM3Test";
EXPECT_EQ(REPOERR_LOAD_SCENE_MISSING_NODES, testUpload(mongoDbName, corrMatBim3PrjName, "RepoModelImport/BrickWalls_bim3_MissingTexture.bim"));
EXPECT_TRUE(projectExists(mongoDbName, corrMatBim3PrjName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "boost/filesystem.hpp"

using namespace repo::manipulator::modelconvertor;
using namespace repo::test;

static bool testBIMFileImport(
std::string bimFilePath,
Expand All @@ -43,7 +42,7 @@ static bool testBIMFileImport(
modelConvertor->importModel(bimFilePath, impModelErrCode);
if (impModelErrCode != expImpModelErrCode)
{
repoError << "Error from importModel(): " << TestLogging::getStringFromRepoErrorCode((int)impModelErrCode);
repoError << "Error from importModel(): " << (int)impModelErrCode;
return false;
}

Expand All @@ -53,7 +52,7 @@ static bool testBIMFileImport(
auto repoScene = modelConvertor->generateRepoScene(genSceneErrCode);
if (genSceneErrCode != expGenSceneErrCode)
{
repoError << "Error from generateRepoScene(): " << TestLogging::getStringFromRepoErrorCode((int)genSceneErrCode);
repoError << "Error from generateRepoScene(): " << (int)genSceneErrCode;
return false;
}

Expand Down Expand Up @@ -164,51 +163,30 @@ static bool testBIMFileImport(
return true;
};

TEST(RepoModelImport, SupportedFormats)
TEST(RepoModelImport, BIM002ValidFile)
{
TestLogging::printTestTitleString(
"Supported BIM format tests",
"Happy path tests to check for compatability with all of the supported BIM \
file format versions");

TestLogging::printSubTestTitleString("BIM003 file - with textures");
EXPECT_TRUE(testBIMFileImport(
getDataPath("RepoModelImport/BrickWalls_bim3.bim"), 3, 2, 6, true));

TestLogging::printSubTestTitleString("BIM002 file");
EXPECT_TRUE(testBIMFileImport(
getDataPath("RepoModelImport/cube_bim2_navis_2021_repo_4.6.1.bim"), 3, 0, 4));
EXPECT_TRUE(testBIMFileImport(getDataPath("RepoModelImport/cube_bim2_navis_2021_repo_4.6.1.bim"), 3, 0, 4));
}

TEST(RepoModelImport, UnsupportedFormats)
TEST(RepoModelImport, BIM003ValidFile)
{
TestLogging::printTestTitleString(
"Unsupported BIM file format",
"Checking to see if the right errors get thrown");
EXPECT_TRUE(testBIMFileImport(getDataPath("RepoModelImport/BrickWalls_bim3.bim"), 3, 2, 6, true));
}

TestLogging::printSubTestTitleString("BIM001 file - testing for unsupported error");
TEST(RepoModelImport, BIM001ValidFile)
{
EXPECT_TRUE(testBIMFileImport(
getDataPath("RepoModelImport/cube_bim1_spoofed.bim"), 0, 0, 0, false, REPOERR_UNSUPPORTED_BIM_VERSION, REPOERR_OK, false));
}

TEST(RepoModelImport, MissingTextureFields)
TEST(RepoModelImport, BIM003MissingTextureFields)
{
TestLogging::printTestTitleString(
"Texture fields missing in the BIM JSON",
"Check to see if the correct error is generated");

TestLogging::printSubTestTitleString("Missing \"numImageBytes\" field");
EXPECT_FALSE(testBIMFileImport(
getDataPath("RepoModelImport/BrickWalls_bim3_CorruptedTextureField.bim"), 3, 1, 6, true, REPOERR_OK, REPOERR_LOAD_SCENE_MISSING_TEXTURE));
}

TEST(RepoModelImport, MissingReferencedTexture)
TEST(RepoModelImport, BIM003MissingReferencedTexture)
{
TestLogging::printTestTitleString(
"Materials references a missing texture",
"Check to see if the correct error is generated");

TestLogging::printSubTestTitleString("Material references a texture id not included in file");
EXPECT_FALSE(testBIMFileImport(
getDataPath("RepoModelImport/BrickWalls_bim3_MissingTexture.bim"), 3, 2, 6, true, REPOERR_OK, REPOERR_LOAD_SCENE_MISSING_TEXTURE));
}
Expand Down
132 changes: 1 addition & 131 deletions test/src/unit/repo_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,134 +198,4 @@ static std::string getRandomString(const uint32_t &iLen)
}

return sStr;
}

namespace repo
{
namespace test
{
class TestLogging
{
public:

static void printTestTitleString(std::string title, std::string description)
{
repoInfo << "============" << title << "============";
repoInfo << description;
}

static void printSubTestTitleString(std::string title)
{
repoInfo << "------------" << title << "------------";
}

static std::string getStringFromRepoErrorCode(int repoErrorCode)
{
std::string errorString = "";
switch(repoErrorCode)
{
case REPOERR_OK:
errorString = R"(Completed successfully)";
break;
case REPOERR_LAUNCHING_COMPUTE_CLIENT:
errorString = R"(Bouncer failed to start - this never gets returned by bouncer client, but bouncer worker will return this)";
break;
case REPOERR_AUTH_FAILED:
errorString = R"(authentication to database failed)";
break;
case REPOERR_UNKNOWN_CMD:
errorString = R"(unrecognised command)";
break;
case REPOERR_UNKNOWN_ERR:
errorString = R"(unknown error (caught exception))";
break;
case REPOERR_LOAD_SCENE_FAIL:
errorString = R"(failed to import file to scene)";
break;
case REPOERR_STASH_GEN_FAIL:
errorString = R"(failed to generate stash graph)";
break;
case REPOERR_LOAD_SCENE_MISSING_TEXTURE:
errorString = R"(Scene uploaded, but missing texture)";
break;
case REPOERR_INVALID_ARG:
errorString = R"(invalid arguments to function)";
break;
case REPOERR_FED_GEN_FAIL:
errorString = R"(failed to generate federation)";
break;
case REPOERR_LOAD_SCENE_MISSING_NODES:
errorString = R"(Scene uploaded but missing some nodes)";
break;
case REPOERR_GET_FILE_FAILED:
errorString = R"(Failed to get file from project)";
break;
case REPOERR_CRASHED:
errorString = R"(Failed to finish (i.e. crashed))";
break;
case REPOERR_PARAM_FILE_READ_FAILED:
errorString = R"(Failed to read import parameters from file (Unity))";
break;
case REPOERR_BUNDLE_GEN_FAILED:
errorString = R"(Failed to generate asset bundles (Unity))";
break;
case REPOERR_LOAD_SCENE_INVALID_MESHES:
errorString = R"(Scene loaded, has untriangulated meshes)";
break;
case REPOERR_ARG_FILE_FAIL:
errorString = R"(Failed to read the fail containing model information)";
break;
case REPOERR_NO_MESHES:
errorString = R"(The file loaded has no meshes)";
break;
case REPOERR_FILE_TYPE_NOT_SUPPORTED:
errorString = R"(Unsupported file extension)";
break;
case REPOERR_MODEL_FILE_READ:
errorString = R"(Failed to read model file)";
break;
case REPOERR_FILE_ASSIMP_GEN:
errorString = R"(Failed during assimp generation)";
break;
case REPOERR_FILE_IFC_GEO_GEN:
errorString = R"(Failed during IFC geometry generation)";
break;
case REPOERR_UNSUPPORTED_BIM_VERSION:
errorString = R"(Bim file version unsupported)";
break;
case REPOERR_UNSUPPORTED_FBX_VERSION:
errorString = R"(FBX file version unsupported)";
break;
case REPOERR_UNSUPPORTED_VERSION:
errorString = R"(Unsupported file version (generic))";
break;
case REPOERR_MAX_NODES_EXCEEDED:
errorString = R"(Exceed the maximum amount fo nodes)";
break;
case REPOERR_ODA_UNAVAILABLE:
errorString = R"(When ODA not compiled in but dgn import requested)";
break;
case REPOERR_VALID_3D_VIEW_NOT_FOUND:
errorString = R"(No valid 3D view found (for Revit format))";
break;
case REPOERR_INVALID_CONFIG_FILE:
errorString = R"(Failed reading configuration file)";
break;
case REPOERR_TIMEOUT:
errorString = R"(Process timed out (only used in bouncer_worker))";
break;
case REPOERR_SYNCHRO_UNAVAILABLE:
errorString = R"(When Synchro is not compiled within the library)";
break;
case REPOERR_SYNCHRO_SEQUENCE_TOO_BIG:
errorString = R"(Synchro sequence exceed size of bson)";
break;
case REPOERR_UPLOAD_FAILED:
errorString = R"(Imported successfully, but failed to upload it to the database/fileshares)";
}
return errorString;
}
};
}
}

}

0 comments on commit 6f5db15

Please sign in to comment.