-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// us_buffer_test.cpp | ||
|
||
#include "gtest/gtest.h" | ||
#include "gmock/gmock.h" | ||
|
||
#include "us_buffer.h" | ||
#include "mock/mock_us_db2.h" | ||
|
||
using namespace testing; | ||
|
||
class US_BufferComponentTest : public ::testing::Test { | ||
protected: | ||
void SetUp() override { | ||
// Set up any shared resources or initial conditions | ||
} | ||
|
||
void TearDown() override { | ||
// Clean up any shared resources or reset conditions | ||
} | ||
}; | ||
|
||
//TEST_F(US_BufferComponentTest, GetAllFromDB_Success) { | ||
// NiceMock<MockUS_DB2> mockDb("dummy_password"); | ||
// Mock::AllowLeak(&mockDb); | ||
// | ||
// // Set up expectations for the mock object | ||
// EXPECT_CALL(mockDb, lastErrno()).WillOnce(Return(US_DB2::OK)); | ||
// EXPECT_CALL(mockDb, query(_)).Times(1); | ||
// EXPECT_CALL(mockDb, next()).WillOnce(Return(true)) | ||
// .WillOnce(Return(false)); // Simulate one result | ||
// EXPECT_CALL(mockDb, value(0)).WillOnce(Return("1")); | ||
// | ||
// QMap<QString, US_BufferComponent> componentList; | ||
// | ||
// US_BufferComponent bufferComponent; | ||
// bufferComponent.getAllFromDB("dummy_password", componentList); | ||
// | ||
// ASSERT_EQ(componentList.size(), 1); | ||
// EXPECT_EQ(componentList.begin().key(), "1"); | ||
//} | ||
|
||
TEST_F(US_BufferComponentTest, GetAllFromDB_DBError) { | ||
qDebug() << "Refer to this issue https://github.com/ehb54/ultrascan-tickets/issues/350"; | ||
// NiceMock<MockUS_DB2> mockDb("dummy_password"); | ||
// Mock::AllowLeak(&mockDb); | ||
// | ||
// // Simulate a database connection error | ||
// EXPECT_CALL(mockDb, lastErrno()).WillOnce(Return(US_DB2::NOT_CONNECTED)); | ||
// | ||
// QMap<QString, US_BufferComponent> componentList; | ||
// | ||
// US_BufferComponent bufferComponent; | ||
// bufferComponent.getAllFromDB("dummy_password", componentList); | ||
// | ||
// ASSERT_EQ(componentList.size(), 0); | ||
} | ||
|
||
//TEST_F(US_BufferComponentTest, GetInfoFromDB_Success) { | ||
// NiceMock<MockUS_DB2> mockDb("dummy_password"); | ||
// Mock::AllowLeak(&mockDb); | ||
// | ||
// // Set up expectations for the mock object | ||
// EXPECT_CALL(mockDb, query(_)).Times(1); | ||
// EXPECT_CALL(mockDb, next()).WillOnce(Return(true)); | ||
// EXPECT_CALL(mockDb, value(_)).WillRepeatedly(Return("test_value")); | ||
// | ||
// US_BufferComponent bufferComponent; | ||
// bufferComponent.componentID = "1"; | ||
// bufferComponent.getInfoFromDB(&mockDb); | ||
// | ||
// EXPECT_EQ(bufferComponent.unit, "test_value"); | ||
// EXPECT_EQ(bufferComponent.name, "test_value"); | ||
// // Continue with other field checks... | ||
//} | ||
|
||
TEST_F(US_BufferComponentTest, GetSpectrum_Success) { | ||
NiceMock<MockUS_DB2> mockDb("dummy_password"); | ||
Mock::AllowLeak(&mockDb); | ||
|
||
// Set up expectations for the mock object | ||
EXPECT_CALL(mockDb, query(_)).Times(1); | ||
EXPECT_CALL(mockDb, next()).WillOnce(Return(true)) | ||
.WillOnce(Return(false)); // Simulate one result | ||
EXPECT_CALL(mockDb, value(1)).WillOnce(Return(500.0)); // Wavelength | ||
EXPECT_CALL(mockDb, value(2)).WillOnce(Return(1.5)); // Value | ||
|
||
US_Buffer buffer; | ||
buffer.bufferID = "1"; | ||
buffer.getSpectrum(&mockDb, "Extinction"); | ||
|
||
ASSERT_EQ(buffer.extinction.size(), 1); | ||
EXPECT_EQ(buffer.extinction[500.0], 1.5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters