Skip to content

Commit

Permalink
Add some bitfield tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeans289 committed Apr 10, 2023
1 parent 823eea4 commit 1368b75
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/SIM_test_varserv/models/test_client/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,33 @@ TEST_F (VariableServerTest, ListSize) {
}


TEST_F (VariableServerTest, bitfields) {
if (socket_status != 0) {
FAIL();
}

socket << "trick.var_send_once(\"vsx.vst.my_bitfield.var1,vsx.vst.my_bitfield.var2,vsx.vst.my_bitfield.var3,vsx.vst.my_bitfield.var4\", 4)\n";
std::string reply_str;
socket >> reply_str;

EXPECT_EQ(strcmp_IgnoringWhiteSpace(reply_str, "5 3 -128 0 2112"), 0);

socket << "trick.var_binary()\ntrick.var_send_once(\"vsx.vst.my_bitfield.var1,vsx.vst.my_bitfield.var2,vsx.vst.my_bitfield.var3,vsx.vst.my_bitfield.var4\", 4)\n";

std::vector<unsigned char> reply = socket.receive_bytes();

ParsedBinaryMessage message;
try {
message.parse(reply);
} catch (const MalformedMessageException& ex) {
FAIL() << "Parser threw an exception: " << ex.what();
}

for (int i = 0; i < message.getNumVars(); i++) {
EXPECT_TRUE(message.variables[i].getType() == 12 || message.variables[i].getType() == 13);
}
}

TEST_F (VariableServerTest, transmit_file) {
if (socket_status != 0) {
FAIL();
Expand Down
10 changes: 10 additions & 0 deletions test/SIM_test_varserv/models/varserv/include/VS.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ PROGRAMMERS: ( (Lindsay Landry) (L3) (9-12-2013) ) ( (Jackie Dea
#ifndef VS_HH
#define VS_HH

typedef struct {
unsigned char var1 :3;
short var2 :8;
int var3 :9;
unsigned int var4 :12;
} bitfield;


class VSTest {
public:
char a;
Expand All @@ -33,6 +41,8 @@ class VSTest {
char * p;
wchar_t * q; /**< trick_chkpnt_io(**) */

bitfield my_bitfield;

int large_arr[4000];

int blocked_from_input; /** trick_io(*o) */
Expand Down
8 changes: 8 additions & 0 deletions test/SIM_test_varserv/models/varserv/src/VS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ int VSTest::default_vars() {
large_arr[i] = i;
}

/* Mixed Types */
// 3,-128,0,2112
my_bitfield.var1 = (1 << (3 - 1)) - 1;
my_bitfield.var2 = -(1 << (8 - 1));
my_bitfield.var3 = 0;
my_bitfield.var4 = (1 << (12 - 1)) + (1 << 12/2);;


blocked_from_input = 500;
blocked_from_output = 1000;

Expand Down

0 comments on commit 1368b75

Please sign in to comment.