Skip to content

Commit

Permalink
History object tests (#4314)
Browse files Browse the repository at this point in the history
* Adds History object tests

* Updated blob tests to use a non-pointer variable
  • Loading branch information
acpaquette authored Mar 1, 2021
1 parent 54dff2b commit de2a88d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
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;

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

0 comments on commit de2a88d

Please sign in to comment.