Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History object tests #4314

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions isis/src/base/objs/Blob/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Isis {
Blob(const QString &name, const QString &type,
const QString &file);
Blob(const Blob &other);
Blob() = default;
Blob &operator=(const Blob &other);

virtual ~Blob();
Expand Down
37 changes: 37 additions & 0 deletions isis/tests/Fixtures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,4 +959,41 @@ namespace Isis {
testCam = testCube->camera();
}

void HistoryBlob::SetUp() {
TempTestingFiles::SetUp();

std::istringstream hss(R"(
Object = mroctx2isis
IsisVersion = "4.1.0 | 2020-07-01"
ProgramVersion = 2016-06-10
ProgramPath = /Users/acpaquette/repos/ISIS3/build/bin
ExecutionDateTime = 2020-07-01T16:48:40
HostName = Unknown
UserName = acpaquette
Description = "Import an MRO CTX image as an Isis cube"

Group = UserParameters
FROM = /Users/acpaquette/Desktop/J03_045994_1986_XN_18N282W.IMG
TO = /Users/acpaquette/Desktop/J03_045994_1986_XN_18N282W_isis.cub
SUFFIX = 18
FILLGAP = true
End_Group
End_Object)");

hss >> historyPvl;

std::ostringstream ostr;
ostr << historyPvl;
std::string histStr = ostr.str();
int nbytes = histStr.size();

// Don't worry about cleaning up this buffer
// The blob takes ownership of it and handles freeing the memory in
// its decontructor
char *buffer = new char[nbytes];
memcpy(buffer, histStr.c_str(), nbytes);

historyBlob = Blob("IsisCube", "History");
historyBlob.setData(buffer, nbytes);
}
}
8 changes: 8 additions & 0 deletions isis/tests/Fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ class CSMCameraDemFixture : public CSMCubeFixture {

void SetUp() override;
};

class HistoryBlob : public TempTestingFiles {
protected:
Blob historyBlob;
PvlObject historyPvl;

void SetUp() override;
};
}

#endif
48 changes: 48 additions & 0 deletions isis/tests/HistoryTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "Fixtures.h"
#include "History.h"

#include "gmock/gmock.h"

using namespace Isis;

TEST(HistoryTests, HistoryTestsDefaultConstructor) {
History history;

Pvl historyPvl = history.ReturnHist();
EXPECT_EQ(historyPvl.groups(), 0);
}

TEST_F(HistoryBlob, HistoryTestsFromBlob) {
History readHistory(historyBlob);

Pvl historyPvl = readHistory.ReturnHist();
ASSERT_TRUE(historyPvl.hasObject("mroctx2isis"));
EXPECT_TRUE(historyPvl.findObject("mroctx2isis").hasGroup("UserParameters"));
}

TEST_F(HistoryBlob, HistoryTestsAddEntry) {
History history;

history.AddEntry(historyPvl);

Pvl newHistoryPvl = history.ReturnHist();
ASSERT_TRUE(newHistoryPvl.hasObject("mroctx2isis"));
EXPECT_TRUE(newHistoryPvl.findObject("mroctx2isis").hasGroup("UserParameters"));
}

TEST_F(HistoryBlob, HistoryTeststoBlob) {
History history(historyBlob);

Blob *blob = history.toBlob();

std::stringstream os;
char *blob_buffer = blob->getBuffer();
Pvl newHistoryPvl;
for (int i = 0; i < blob->Size(); i++) {
os << blob_buffer[i];
}
os >> newHistoryPvl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't interrogate the Blob itself, I would just test History -> Blob -> History works correctly.

Copy link
Collaborator Author

@acpaquette acpaquette Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? That's testing a lot in one test, which is why I thought chunking the test up would be better.

It seems like we either test all of the functionality of the class in one test that is an end to end test, or we chunk it up like I have. In the end to end test you would use the default constructor, the AddEntry method, the toBlob method, the blob constructor and the ReturnHist method to examine the expect PVL


ASSERT_TRUE(newHistoryPvl.hasObject("mroctx2isis"));
EXPECT_TRUE(newHistoryPvl.findObject("mroctx2isis").hasGroup("UserParameters"));
}