blob: d00bebd743274c033cd1d58caf74880e8e4d1c09 [file] [log] [blame]
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05001#include "common/utils.hpp"
Riya Dixit754041d2024-02-20 06:15:49 -06002#include "mocked_utils.hpp"
George Liu6492f522020-06-16 10:34:05 +08003
George Liuc453e162022-12-21 17:16:23 +08004#include <libpldm/platform.h>
Gilbert Chen6c7fed42022-02-22 15:40:17 +00005#include <linux/mctp.h>
George Liuc453e162022-12-21 17:16:23 +08006
George Liu83409572019-12-24 18:42:54 +08007#include <gtest/gtest.h>
8
9using namespace pldm::utils;
10
Riya Dixit754041d2024-02-20 06:15:49 -060011TEST(GetInventoryObjects, testForEmptyObject)
12{
13 ObjectValueTree result =
14 DBusHandler::getInventoryObjects<GetManagedEmptyObject>();
15 EXPECT_TRUE(result.empty());
16}
17
18TEST(GetInventoryObjects, testForObject)
19{
20 std::string path = "/foo/bar";
21 std::string service = "foo.bar";
22 auto result = DBusHandler::getInventoryObjects<GetManagedObject>();
23 EXPECT_EQ(result[path].begin()->first, service);
24 auto function =
25 std::get<bool>(result[path][service][std::string("Functional")]);
26 auto model =
27 std::get<std::string>(result[path][service][std::string("Model")]);
28 EXPECT_FALSE(result.empty());
29 EXPECT_TRUE(function);
30 EXPECT_EQ(model, std::string("1234 - 00Z"));
31}
32
Manojkiran Edacd4cd452024-04-23 08:53:17 +053033TEST(printBuffer, testprintBufferGoodPath)
34{
35 std::vector<uint8_t> buffer = {10, 12, 14, 25, 233};
36 std::ostringstream localString;
37 auto coutBuffer = std::cout.rdbuf();
38 std::cout.rdbuf(localString.rdbuf());
39 printBuffer(false, buffer);
40 std::cout.rdbuf(coutBuffer);
41 EXPECT_EQ(localString.str(), "Rx: 0a 0c 0e 19 e9 \n");
42 localString.str("");
43 localString.clear();
44 std::cerr << localString.str() << std::endl;
45 buffer = {12, 0, 200, 12, 255};
46 std::cout.rdbuf(localString.rdbuf());
47 printBuffer(true, buffer);
48 std::cout.rdbuf(coutBuffer);
49 EXPECT_EQ(localString.str(), "Tx: 0c 00 c8 0c ff \n");
50}
51
52TEST(printBuffer, testprintBufferBadPath)
53{
54 std::vector<uint8_t> buffer = {};
55 std::ostringstream localString;
56 auto coutBuffer = std::cout.rdbuf();
57 std::cout.rdbuf(localString.rdbuf());
58 printBuffer(false, buffer);
59 EXPECT_EQ(localString.str(), "");
60 printBuffer(true, buffer);
61 std::cout.rdbuf(coutBuffer);
62 EXPECT_EQ(localString.str(), "");
63}
64
George Liu83409572019-12-24 18:42:54 +080065TEST(decodeDate, testGooduintToDate)
66{
67 uint64_t data = 20191212115959;
68 uint16_t year = 2019;
69 uint8_t month = 12;
70 uint8_t day = 12;
71 uint8_t hours = 11;
72 uint8_t minutes = 59;
73 uint8_t seconds = 59;
74
75 uint16_t retyear = 0;
76 uint8_t retmonth = 0;
77 uint8_t retday = 0;
78 uint8_t rethours = 0;
79 uint8_t retminutes = 0;
80 uint8_t retseconds = 0;
81
82 auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours,
83 &retminutes, &retseconds);
84
85 EXPECT_EQ(ret, true);
86 EXPECT_EQ(year, retyear);
87 EXPECT_EQ(month, retmonth);
88 EXPECT_EQ(day, retday);
89 EXPECT_EQ(hours, rethours);
90 EXPECT_EQ(minutes, retminutes);
91 EXPECT_EQ(seconds, retseconds);
92}
93
94TEST(decodeDate, testBaduintToDate)
95{
96 uint64_t data = 10191212115959;
97
98 uint16_t retyear = 0;
99 uint8_t retmonth = 0;
100 uint8_t retday = 0;
101 uint8_t rethours = 0;
102 uint8_t retminutes = 0;
103 uint8_t retseconds = 0;
104
105 auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours,
106 &retminutes, &retseconds);
107
108 EXPECT_EQ(ret, false);
109}
110
George Liuba4c1fb2020-02-05 14:13:30 +0800111TEST(parseEffecterData, testGoodDecodeEffecterData)
George Liu83409572019-12-24 18:42:54 +0800112{
George Liuba4c1fb2020-02-05 14:13:30 +0800113 std::vector<uint8_t> effecterData = {1, 1, 0, 1};
114 uint8_t effecterCount = 2;
George Liu83409572019-12-24 18:42:54 +0800115 set_effecter_state_field stateField0 = {1, 1};
George Liuba4c1fb2020-02-05 14:13:30 +0800116 set_effecter_state_field stateField1 = {0, 1};
George Liu83409572019-12-24 18:42:54 +0800117
George Liuba4c1fb2020-02-05 14:13:30 +0800118 auto effecterField = parseEffecterData(effecterData, effecterCount);
119 EXPECT_NE(effecterField, std::nullopt);
120 EXPECT_EQ(effecterCount, effecterField->size());
George Liu83409572019-12-24 18:42:54 +0800121
George Liuba4c1fb2020-02-05 14:13:30 +0800122 std::vector<set_effecter_state_field> stateField = effecterField.value();
George Liu83409572019-12-24 18:42:54 +0800123 EXPECT_EQ(stateField[0].set_request, stateField0.set_request);
124 EXPECT_EQ(stateField[0].effecter_state, stateField0.effecter_state);
125 EXPECT_EQ(stateField[1].set_request, stateField1.set_request);
126 EXPECT_EQ(stateField[1].effecter_state, stateField1.effecter_state);
George Liu83409572019-12-24 18:42:54 +0800127}
128
George Liuba4c1fb2020-02-05 14:13:30 +0800129TEST(parseEffecterData, testBadDecodeEffecterData)
George Liu83409572019-12-24 18:42:54 +0800130{
George Liuba4c1fb2020-02-05 14:13:30 +0800131 std::vector<uint8_t> effecterData = {0, 1, 0, 1, 0, 1};
132 uint8_t effecterCount = 2;
George Liu83409572019-12-24 18:42:54 +0800133
George Liuba4c1fb2020-02-05 14:13:30 +0800134 auto effecterField = parseEffecterData(effecterData, effecterCount);
George Liu83409572019-12-24 18:42:54 +0800135
George Liuba4c1fb2020-02-05 14:13:30 +0800136 EXPECT_EQ(effecterField, std::nullopt);
George Liu83409572019-12-24 18:42:54 +0800137}
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500138
139TEST(FindStateEffecterPDR, testOneMatch)
140{
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500141 auto repo = pldm_pdr_init();
142 uint8_t tid = 1;
143 uint16_t entityID = 33;
144 uint16_t stateSetId = 196;
145
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400146 std::vector<uint8_t> pdr(
147 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
148 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500149
150 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
151
152 auto state =
153 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
154
155 rec->hdr.type = 11;
156 rec->hdr.record_handle = 1;
157 rec->entity_type = 33;
158 rec->container_id = 0;
159 rec->composite_effecter_count = 1;
160 state->state_set_id = 196;
161 state->possible_states_size = 1;
162
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930163 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000164 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500165
166 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
167
168 EXPECT_EQ(pdr, record[0]);
169
170 pldm_pdr_destroy(repo);
171}
172
173TEST(FindStateEffecterPDR, testNoMatch)
174{
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500175 auto repo = pldm_pdr_init();
176 uint8_t tid = 1;
177 uint16_t entityID = 44;
178 uint16_t stateSetId = 196;
179
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400180 std::vector<uint8_t> pdr(
181 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
182 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500183
184 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
185
186 auto state =
187 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
188
189 rec->hdr.type = 11;
190 rec->hdr.record_handle = 1;
191 rec->entity_type = 33;
192 rec->container_id = 0;
193 rec->composite_effecter_count = 1;
194 state->state_set_id = 196;
195 state->possible_states_size = 1;
196
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930197 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000198 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500199
200 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
201
202 EXPECT_EQ(record.empty(), true);
203
204 pldm_pdr_destroy(repo);
205}
206
207TEST(FindStateEffecterPDR, testEmptyRepo)
208{
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500209 auto repo = pldm_pdr_init();
210 uint8_t tid = 1;
211 uint16_t entityID = 33;
212 uint16_t stateSetId = 196;
213
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400214 std::vector<uint8_t> pdr(
215 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
216 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500217
218 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
219
220 EXPECT_EQ(record.empty(), true);
221
222 pldm_pdr_destroy(repo);
223}
224
225TEST(FindStateEffecterPDR, testMoreMatch)
226{
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500227 auto repo = pldm_pdr_init();
228 uint8_t tid = 1;
229
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400230 std::vector<uint8_t> pdr(
231 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
232 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500233
234 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
235
236 auto state =
237 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
238
239 rec->hdr.type = 11;
240 rec->hdr.record_handle = 1;
241 rec->entity_type = 31;
242 rec->container_id = 0;
243 rec->composite_effecter_count = 1;
244 state->state_set_id = 129;
245 state->possible_states_size = 1;
246
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930247 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000248 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500249
250 std::vector<uint8_t> pdr_second(
251 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
252 sizeof(struct state_effecter_possible_states));
253
254 auto rec_second =
255 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
256
257 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
258 rec_second->possible_states);
259
260 rec_second->hdr.type = 11;
261 rec_second->hdr.record_handle = 2;
262 rec_second->entity_type = 31;
263 rec_second->container_id = 0;
264 rec_second->composite_effecter_count = 1;
265 state_second->state_set_id = 129;
266 state_second->possible_states_size = 1;
267
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930268 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000269 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
270 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930271 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500272
273 uint16_t entityID_ = 31;
274 uint16_t stateSetId_ = 129;
275
276 auto record = findStateEffecterPDR(tid, entityID_, stateSetId_, repo);
277
278 EXPECT_EQ(pdr, record[0]);
279 EXPECT_EQ(pdr_second, record[1]);
280
281 pldm_pdr_destroy(repo);
282}
283
284TEST(FindStateEffecterPDR, testManyNoMatch)
285{
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500286 auto repo = pldm_pdr_init();
287 uint8_t tid = 1;
288 uint16_t entityID = 33;
289 uint16_t stateSetId = 196;
290
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400291 std::vector<uint8_t> pdr(
292 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
293 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500294
295 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
296
297 auto state =
298 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
299
300 rec->hdr.type = 11;
301 rec->hdr.record_handle = 1;
302 rec->entity_type = 34;
303 rec->container_id = 0;
304 rec->composite_effecter_count = 1;
305 state->state_set_id = 198;
306 state->possible_states_size = 1;
307
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930308 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000309 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500310
311 std::vector<uint8_t> pdr_second(
312 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
313 sizeof(struct state_effecter_possible_states));
314
315 auto rec_second =
316 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
317
318 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
319 rec_second->possible_states);
320
321 rec_second->hdr.type = 11;
322 rec_second->hdr.record_handle = 2;
323 rec_second->entity_type = 39;
324 rec_second->container_id = 0;
325 rec_second->composite_effecter_count = 1;
326 state_second->state_set_id = 169;
327 state_second->possible_states_size = 1;
328
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930329 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000330 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
331 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930332 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500333
334 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
335
336 EXPECT_EQ(record.empty(), true);
337
338 pldm_pdr_destroy(repo);
339}
340
341TEST(FindStateEffecterPDR, testOneMatchOneNoMatch)
342{
343 auto repo = pldm_pdr_init();
344 uint8_t tid = 1;
345 uint16_t entityID = 67;
346 uint16_t stateSetId = 192;
347
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400348 std::vector<uint8_t> pdr(
349 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
350 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500351
352 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
353
354 auto state =
355 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
356
357 rec->hdr.type = 11;
358 rec->hdr.record_handle = 1;
359 rec->entity_type = 32;
360 rec->container_id = 0;
361 rec->composite_effecter_count = 1;
362 state->state_set_id = 198;
363 state->possible_states_size = 1;
364
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930365 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000366 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500367
368 std::vector<uint8_t> pdr_second(
369 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
370 sizeof(struct state_effecter_possible_states));
371
372 auto rec_second =
373 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
374
375 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
376 rec_second->possible_states);
377
378 rec_second->hdr.type = 11;
379 rec_second->hdr.record_handle = 2;
380 rec_second->entity_type = 67;
381 rec_second->container_id = 0;
382 rec_second->composite_effecter_count = 1;
383 state_second->state_set_id = 192;
384 state_second->possible_states_size = 1;
385
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930386 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000387 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
388 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930389 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500390
391 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
392
393 EXPECT_EQ(pdr_second, record[0]);
394 EXPECT_EQ(record.size(), 1);
395
396 pldm_pdr_destroy(repo);
397}
398
399TEST(FindStateEffecterPDR, testOneMatchManyNoMatch)
400{
401 auto repo = pldm_pdr_init();
402 uint8_t tid = 1;
403 uint16_t entityID = 67;
404 uint16_t stateSetId = 192;
405
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400406 std::vector<uint8_t> pdr(
407 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
408 sizeof(struct state_effecter_possible_states));
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500409
410 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
411
412 auto state =
413 reinterpret_cast<state_effecter_possible_states*>(rec->possible_states);
414
415 rec->hdr.type = 11;
416 rec->hdr.record_handle = 1;
417 rec->entity_type = 32;
418 rec->container_id = 0;
419 rec->composite_effecter_count = 1;
420 state->state_set_id = 198;
421 state->possible_states_size = 1;
422
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930423 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000424 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500425
426 std::vector<uint8_t> pdr_second(
427 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
428 sizeof(struct state_effecter_possible_states));
429
430 auto rec_second =
431 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_second.data());
432
433 auto state_second = reinterpret_cast<state_effecter_possible_states*>(
434 rec_second->possible_states);
435
436 rec_second->hdr.type = 11;
437 rec_second->hdr.record_handle = 2;
438 rec_second->entity_type = 67;
439 rec_second->container_id = 0;
440 rec_second->composite_effecter_count = 1;
441 state_second->state_set_id = 192;
442 state_second->possible_states_size = 1;
443
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930444 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000445 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
446 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930447 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500448
449 std::vector<uint8_t> pdr_third(
450 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
451 sizeof(struct state_effecter_possible_states));
452
453 auto rec_third =
454 reinterpret_cast<pldm_state_effecter_pdr*>(pdr_third.data());
455
456 auto state_third = reinterpret_cast<state_effecter_possible_states*>(
457 rec_third->possible_states);
458
459 rec_third->hdr.type = 11;
460 rec_third->hdr.record_handle = 3;
461 rec_third->entity_type = 69;
462 rec_third->container_id = 0;
463 rec_third->composite_effecter_count = 1;
464 state_third->state_set_id = 199;
465 state_third->possible_states_size = 1;
466
467 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
468
469 EXPECT_EQ(pdr_second, record[0]);
470 EXPECT_EQ(record.size(), 1);
471
472 pldm_pdr_destroy(repo);
473}
474
475TEST(FindStateEffecterPDR, testCompositeEffecter)
476{
477 auto repo = pldm_pdr_init();
478 uint8_t tid = 1;
479 uint16_t entityID = 67;
480 uint16_t stateSetId = 192;
481
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400482 std::vector<uint8_t> pdr(
483 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
484 sizeof(struct state_effecter_possible_states) * 3);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500485
486 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
Chicago Duana7aacc32020-06-10 18:03:38 +0800487 auto state_start = rec->possible_states;
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500488
Chicago Duana7aacc32020-06-10 18:03:38 +0800489 auto state = reinterpret_cast<state_effecter_possible_states*>(state_start);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500490
491 rec->hdr.type = 11;
492 rec->hdr.record_handle = 1;
493 rec->entity_type = 67;
494 rec->container_id = 0;
495 rec->composite_effecter_count = 3;
496 state->state_set_id = 198;
497 state->possible_states_size = 1;
498
Chicago Duana7aacc32020-06-10 18:03:38 +0800499 state_start += state->possible_states_size + sizeof(state->state_set_id) +
500 sizeof(state->possible_states_size);
501 state = reinterpret_cast<state_effecter_possible_states*>(state_start);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500502 state->state_set_id = 193;
503 state->possible_states_size = 1;
504
Chicago Duana7aacc32020-06-10 18:03:38 +0800505 state_start += state->possible_states_size + sizeof(state->state_set_id) +
506 sizeof(state->possible_states_size);
507 state = reinterpret_cast<state_effecter_possible_states*>(state_start);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500508 state->state_set_id = 192;
509 state->possible_states_size = 1;
510
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930511 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000512 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500513
514 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
515
516 EXPECT_EQ(pdr, record[0]);
517
518 pldm_pdr_destroy(repo);
519}
520
521TEST(FindStateEffecterPDR, testNoMatchCompositeEffecter)
522{
523 auto repo = pldm_pdr_init();
524 uint8_t tid = 1;
525 uint16_t entityID = 67;
526 uint16_t stateSetId = 192;
527
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400528 std::vector<uint8_t> pdr(
529 sizeof(struct pldm_state_effecter_pdr) - sizeof(uint8_t) +
530 sizeof(struct state_effecter_possible_states) * 3);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500531
532 auto rec = reinterpret_cast<pldm_state_effecter_pdr*>(pdr.data());
Chicago Duana7aacc32020-06-10 18:03:38 +0800533 auto state_start = rec->possible_states;
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500534
Chicago Duana7aacc32020-06-10 18:03:38 +0800535 auto state = reinterpret_cast<state_effecter_possible_states*>(state_start);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500536
537 rec->hdr.type = 11;
538 rec->hdr.record_handle = 1;
539 rec->entity_type = 34;
540 rec->container_id = 0;
541 rec->composite_effecter_count = 3;
542 state->state_set_id = 198;
543 state->possible_states_size = 1;
544
Chicago Duana7aacc32020-06-10 18:03:38 +0800545 state_start += state->possible_states_size + sizeof(state->state_set_id) +
546 sizeof(state->possible_states_size);
547 state = reinterpret_cast<state_effecter_possible_states*>(state_start);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500548 state->state_set_id = 193;
549 state->possible_states_size = 1;
550
Chicago Duana7aacc32020-06-10 18:03:38 +0800551 state_start += state->possible_states_size + sizeof(state->state_set_id) +
552 sizeof(state->possible_states_size);
553 state = reinterpret_cast<state_effecter_possible_states*>(state_start);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500554 state->state_set_id = 123;
555 state->possible_states_size = 1;
556
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930557 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000558 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500559
560 auto record = findStateEffecterPDR(tid, entityID, stateSetId, repo);
561
562 EXPECT_EQ(record.empty(), true);
563
564 pldm_pdr_destroy(repo);
565}
Chicago Duan738e4d82020-05-28 16:39:19 +0800566
567TEST(FindStateSensorPDR, testOneMatch)
568{
Chicago Duan738e4d82020-05-28 16:39:19 +0800569 auto repo = pldm_pdr_init();
570 uint8_t tid = 1;
571 uint16_t entityID = 5;
572 uint16_t stateSetId = 1;
573
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400574 std::vector<uint8_t> pdr(
575 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
576 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800577
578 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
579
580 auto state =
581 reinterpret_cast<state_sensor_possible_states*>(rec->possible_states);
582
583 rec->hdr.type = 4;
584 rec->hdr.record_handle = 1;
585 rec->entity_type = 5;
586 rec->container_id = 0;
587 rec->composite_sensor_count = 1;
588 state->state_set_id = 1;
589 state->possible_states_size = 1;
590
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930591 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000592 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800593
594 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
595
596 EXPECT_EQ(pdr, record[0]);
597
598 pldm_pdr_destroy(repo);
599}
600
601TEST(FindStateSensorPDR, testNoMatch)
602{
Chicago Duan738e4d82020-05-28 16:39:19 +0800603 auto repo = pldm_pdr_init();
604 uint8_t tid = 1;
605 uint16_t entityID = 5;
606 uint16_t stateSetId = 1;
607
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400608 std::vector<uint8_t> pdr(
609 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
610 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800611
612 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
613
614 auto state =
615 reinterpret_cast<state_sensor_possible_states*>(rec->possible_states);
616
617 rec->hdr.type = 4;
618 rec->hdr.record_handle = 1;
619 rec->entity_type = 55;
620 rec->container_id = 0;
621 rec->composite_sensor_count = 1;
622 state->state_set_id = 1;
623 state->possible_states_size = 1;
624
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930625 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000626 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800627
628 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
629
630 EXPECT_EQ(record.empty(), true);
631
632 pldm_pdr_destroy(repo);
633}
634
635TEST(FindStateSensorPDR, testEmptyRepo)
636{
Chicago Duan738e4d82020-05-28 16:39:19 +0800637 auto repo = pldm_pdr_init();
638 uint8_t tid = 1;
639 uint16_t entityID = 5;
640 uint16_t stateSetId = 1;
641
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400642 std::vector<uint8_t> pdr(
643 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
644 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800645
646 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
647
648 EXPECT_EQ(record.empty(), true);
649
650 pldm_pdr_destroy(repo);
651}
652
653TEST(FindStateSensorPDR, testMoreMatch)
654{
Chicago Duan738e4d82020-05-28 16:39:19 +0800655 auto repo = pldm_pdr_init();
656 uint8_t tid = 1;
657
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400658 std::vector<uint8_t> pdr(
659 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
660 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800661
662 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
663
664 auto state =
665 reinterpret_cast<state_sensor_possible_states*>(rec->possible_states);
666
667 rec->hdr.type = 4;
668 rec->hdr.record_handle = 1;
669 rec->entity_type = 5;
670 rec->container_id = 0;
671 rec->composite_sensor_count = 1;
672 state->state_set_id = 1;
673 state->possible_states_size = 1;
674
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930675 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000676 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800677
678 std::vector<uint8_t> pdr_second(
679 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
680 sizeof(struct state_sensor_possible_states));
681
682 auto rec_second =
683 reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data());
684
685 auto state_second = reinterpret_cast<state_sensor_possible_states*>(
686 rec_second->possible_states);
687
688 rec_second->hdr.type = 4;
689 rec_second->hdr.record_handle = 2;
690 rec_second->entity_type = 5;
691 rec_second->container_id = 0;
692 rec_second->composite_sensor_count = 1;
693 state_second->state_set_id = 1;
694 state_second->possible_states_size = 1;
695
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930696 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000697 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
698 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930699 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800700
701 uint16_t entityID_ = 5;
702 uint16_t stateSetId_ = 1;
703
704 auto record = findStateSensorPDR(tid, entityID_, stateSetId_, repo);
705
706 EXPECT_EQ(pdr, record[0]);
707 EXPECT_EQ(pdr_second, record[1]);
708
709 pldm_pdr_destroy(repo);
710}
711
712TEST(FindStateSensorPDR, testManyNoMatch)
713{
Chicago Duan738e4d82020-05-28 16:39:19 +0800714 auto repo = pldm_pdr_init();
715 uint8_t tid = 1;
716 uint16_t entityID = 5;
717 uint16_t stateSetId = 1;
718
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400719 std::vector<uint8_t> pdr(
720 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
721 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800722
723 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
724
725 auto state =
726 reinterpret_cast<state_sensor_possible_states*>(rec->possible_states);
727
728 rec->hdr.type = 4;
729 rec->hdr.record_handle = 1;
730 rec->entity_type = 56;
731 rec->container_id = 0;
732 rec->composite_sensor_count = 1;
733 state->state_set_id = 2;
734 state->possible_states_size = 1;
735
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930736 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000737 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800738
739 std::vector<uint8_t> pdr_second(
740 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
741 sizeof(struct state_sensor_possible_states));
742
743 auto rec_second =
744 reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data());
745
746 auto state_second = reinterpret_cast<state_sensor_possible_states*>(
747 rec_second->possible_states);
748
749 rec_second->hdr.type = 4;
750 rec_second->hdr.record_handle = 2;
751 rec_second->entity_type = 66;
752 rec_second->container_id = 0;
753 rec_second->composite_sensor_count = 1;
754 state_second->state_set_id = 3;
755 state_second->possible_states_size = 1;
756
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930757 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000758 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
759 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930760 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800761
762 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
763
764 EXPECT_EQ(record.empty(), true);
765
766 pldm_pdr_destroy(repo);
767}
768
769TEST(FindStateSensorPDR, testOneMatchOneNoMatch)
770{
771 auto repo = pldm_pdr_init();
772 uint8_t tid = 1;
773 uint16_t entityID = 5;
774 uint16_t stateSetId = 1;
775
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400776 std::vector<uint8_t> pdr(
777 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
778 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800779
780 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
781
782 auto state =
783 reinterpret_cast<state_sensor_possible_states*>(rec->possible_states);
784
785 rec->hdr.type = 4;
786 rec->hdr.record_handle = 1;
787 rec->entity_type = 10;
788 rec->container_id = 0;
789 rec->composite_sensor_count = 1;
790 state->state_set_id = 20;
791 state->possible_states_size = 1;
792
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930793 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000794 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800795
796 std::vector<uint8_t> pdr_second(
797 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
798 sizeof(struct state_sensor_possible_states));
799
800 auto rec_second =
801 reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data());
802
803 auto state_second = reinterpret_cast<state_sensor_possible_states*>(
804 rec_second->possible_states);
805
806 rec_second->hdr.type = 4;
807 rec_second->hdr.record_handle = 2;
808 rec_second->entity_type = 5;
809 rec_second->container_id = 0;
810 rec_second->composite_sensor_count = 1;
811 state_second->state_set_id = 1;
812 state_second->possible_states_size = 1;
813
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930814 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000815 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
816 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930817 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800818
819 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
820
821 EXPECT_EQ(pdr_second, record[0]);
822 EXPECT_EQ(record.size(), 1);
823
824 pldm_pdr_destroy(repo);
825}
826
827TEST(FindStateSensorPDR, testOneMatchManyNoMatch)
828{
829 auto repo = pldm_pdr_init();
830 uint8_t tid = 1;
831 uint16_t entityID = 5;
832 uint16_t stateSetId = 1;
833
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400834 std::vector<uint8_t> pdr(
835 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
836 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800837
838 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
839
840 auto state =
841 reinterpret_cast<state_sensor_possible_states*>(rec->possible_states);
842
843 rec->hdr.type = 4;
844 rec->hdr.record_handle = 1;
845 rec->entity_type = 6;
846 rec->container_id = 0;
847 rec->composite_sensor_count = 1;
848 state->state_set_id = 9;
849 state->possible_states_size = 1;
850
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930851 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000852 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800853
854 std::vector<uint8_t> pdr_second(
855 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
856 sizeof(struct state_sensor_possible_states));
857
858 auto rec_second =
859 reinterpret_cast<pldm_state_sensor_pdr*>(pdr_second.data());
860
861 auto state_second = reinterpret_cast<state_sensor_possible_states*>(
862 rec_second->possible_states);
863
864 rec_second->hdr.type = 4;
865 rec_second->hdr.record_handle = 2;
866 rec_second->entity_type = 5;
867 rec_second->container_id = 0;
868 rec_second->composite_sensor_count = 1;
869 state_second->state_set_id = 1;
870 state_second->possible_states_size = 1;
871
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930872 handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000873 ASSERT_EQ(pldm_pdr_add(repo, pdr_second.data(), pdr_second.size(), false, 1,
874 &handle),
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930875 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800876
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400877 std::vector<uint8_t> pdr_third(
878 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
879 sizeof(struct state_sensor_possible_states));
Chicago Duan738e4d82020-05-28 16:39:19 +0800880
881 auto rec_third = reinterpret_cast<pldm_state_sensor_pdr*>(pdr_third.data());
882
883 auto state_third = reinterpret_cast<state_sensor_possible_states*>(
884 rec_third->possible_states);
885
886 rec_third->hdr.type = 4;
887 rec_third->hdr.record_handle = 3;
888 rec_third->entity_type = 7;
889 rec_third->container_id = 0;
890 rec_third->composite_sensor_count = 1;
891 state_third->state_set_id = 12;
892 state_third->possible_states_size = 1;
893
894 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
895
896 EXPECT_EQ(pdr_second, record[0]);
897 EXPECT_EQ(record.size(), 1);
898
899 pldm_pdr_destroy(repo);
900}
901
902TEST(FindStateSensorPDR, testCompositeSensor)
903{
904 auto repo = pldm_pdr_init();
905 uint8_t tid = 1;
906 uint16_t entityID = 5;
907 uint16_t stateSetId = 1;
908
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400909 std::vector<uint8_t> pdr(
910 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
911 sizeof(struct state_sensor_possible_states) * 3);
Chicago Duan738e4d82020-05-28 16:39:19 +0800912
913 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
Chicago Duana7aacc32020-06-10 18:03:38 +0800914 auto state_start = rec->possible_states;
Chicago Duan738e4d82020-05-28 16:39:19 +0800915
Chicago Duana7aacc32020-06-10 18:03:38 +0800916 auto state = reinterpret_cast<state_sensor_possible_states*>(state_start);
Chicago Duan738e4d82020-05-28 16:39:19 +0800917
918 rec->hdr.type = 4;
919 rec->hdr.record_handle = 1;
920 rec->entity_type = 5;
921 rec->container_id = 0;
922 rec->composite_sensor_count = 3;
923 state->state_set_id = 2;
924 state->possible_states_size = 1;
925
Chicago Duana7aacc32020-06-10 18:03:38 +0800926 state_start += state->possible_states_size + sizeof(state->state_set_id) +
927 sizeof(state->possible_states_size);
928 state = reinterpret_cast<state_sensor_possible_states*>(state_start);
929
Chicago Duan738e4d82020-05-28 16:39:19 +0800930 state->state_set_id = 7;
931 state->possible_states_size = 1;
932
Chicago Duana7aacc32020-06-10 18:03:38 +0800933 state_start += state->possible_states_size + sizeof(state->state_set_id) +
934 sizeof(state->possible_states_size);
935 state = reinterpret_cast<state_sensor_possible_states*>(state_start);
936
Chicago Duan738e4d82020-05-28 16:39:19 +0800937 state->state_set_id = 1;
938 state->possible_states_size = 1;
939
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930940 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000941 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800942
943 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
944
945 EXPECT_EQ(pdr, record[0]);
946
947 pldm_pdr_destroy(repo);
948}
949
950TEST(FindStateSensorPDR, testNoMatchCompositeSensor)
951{
952 auto repo = pldm_pdr_init();
953 uint8_t tid = 1;
954 uint16_t entityID = 5;
955 uint16_t stateSetId = 1;
956
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400957 std::vector<uint8_t> pdr(
958 sizeof(struct pldm_state_sensor_pdr) - sizeof(uint8_t) +
959 sizeof(struct state_sensor_possible_states) * 3);
Chicago Duan738e4d82020-05-28 16:39:19 +0800960
961 auto rec = reinterpret_cast<pldm_state_sensor_pdr*>(pdr.data());
Chicago Duana7aacc32020-06-10 18:03:38 +0800962 auto state_start = rec->possible_states;
Chicago Duan738e4d82020-05-28 16:39:19 +0800963
Chicago Duana7aacc32020-06-10 18:03:38 +0800964 auto state = reinterpret_cast<state_sensor_possible_states*>(state_start);
Chicago Duan738e4d82020-05-28 16:39:19 +0800965
966 rec->hdr.type = 4;
967 rec->hdr.record_handle = 1;
968 rec->entity_type = 21;
969 rec->container_id = 0;
970 rec->composite_sensor_count = 3;
971 state->state_set_id = 15;
972 state->possible_states_size = 1;
973
Chicago Duana7aacc32020-06-10 18:03:38 +0800974 state_start += state->possible_states_size + sizeof(state->state_set_id) +
975 sizeof(state->possible_states_size);
976 state = reinterpret_cast<state_sensor_possible_states*>(state_start);
Chicago Duan738e4d82020-05-28 16:39:19 +0800977 state->state_set_id = 19;
978 state->possible_states_size = 1;
979
Chicago Duana7aacc32020-06-10 18:03:38 +0800980 state_start += state->possible_states_size + sizeof(state->state_set_id) +
981 sizeof(state->possible_states_size);
982 state = reinterpret_cast<state_sensor_possible_states*>(state_start);
Chicago Duan738e4d82020-05-28 16:39:19 +0800983 state->state_set_id = 39;
984 state->possible_states_size = 1;
985
Andrew Jeffery64f37fe2023-07-03 15:41:13 +0930986 uint32_t handle = 0;
Andrew Jeffery5a945bd2024-08-01 13:15:36 +0000987 ASSERT_EQ(pldm_pdr_add(repo, pdr.data(), pdr.size(), false, 1, &handle), 0);
Chicago Duan738e4d82020-05-28 16:39:19 +0800988
989 auto record = findStateSensorPDR(tid, entityID, stateSetId, repo);
990
991 EXPECT_EQ(record.empty(), true);
992
993 pldm_pdr_destroy(repo);
Chicago Duana7aacc32020-06-10 18:03:38 +0800994}
Tom Joseph54922072021-06-19 02:45:46 -0700995
996TEST(toString, allTestCases)
997{
998 variable_field buffer{};
999 constexpr std::string_view str1{};
1000 auto returnStr1 = toString(buffer);
1001 EXPECT_EQ(returnStr1, str1);
1002
1003 constexpr std::string_view str2{"0penBmc"};
1004 constexpr std::array<uint8_t, 7> bufferArr1{0x30, 0x70, 0x65, 0x6e,
1005 0x42, 0x6d, 0x63};
1006 buffer.ptr = bufferArr1.data();
1007 buffer.length = bufferArr1.size();
1008 auto returnStr2 = toString(buffer);
1009 EXPECT_EQ(returnStr2, str2);
1010
1011 constexpr std::string_view str3{"0pen mc"};
1012 // \xa0 - the non-breaking space in ISO-8859-1
1013 constexpr std::array<uint8_t, 7> bufferArr2{0x30, 0x70, 0x65, 0x6e,
1014 0xa0, 0x6d, 0x63};
1015 buffer.ptr = bufferArr2.data();
1016 buffer.length = bufferArr2.size();
1017 auto returnStr3 = toString(buffer);
1018 EXPECT_EQ(returnStr3, str3);
George Liu872f0f62021-11-25 16:26:16 +08001019}
1020
1021TEST(Split, allTestCases)
1022{
1023 std::string s1 = "aa,bb,cc,dd";
1024 auto results1 = split(s1, ",");
1025 EXPECT_EQ(results1[0], "aa");
1026 EXPECT_EQ(results1[1], "bb");
1027 EXPECT_EQ(results1[2], "cc");
1028 EXPECT_EQ(results1[3], "dd");
1029
1030 std::string s2 = "aa||bb||cc||dd";
1031 auto results2 = split(s2, "||");
1032 EXPECT_EQ(results2[0], "aa");
1033 EXPECT_EQ(results2[1], "bb");
1034 EXPECT_EQ(results2[2], "cc");
1035 EXPECT_EQ(results2[3], "dd");
1036
1037 std::string s3 = " aa || bb||cc|| dd";
1038 auto results3 = split(s3, "||", " ");
1039 EXPECT_EQ(results3[0], "aa");
1040 EXPECT_EQ(results3[1], "bb");
1041 EXPECT_EQ(results3[2], "cc");
1042 EXPECT_EQ(results3[3], "dd");
1043
1044 std::string s4 = "aa\\\\bb\\cc\\dd";
1045 auto results4 = split(s4, "\\");
1046 EXPECT_EQ(results4[0], "aa");
1047 EXPECT_EQ(results4[1], "bb");
1048 EXPECT_EQ(results4[2], "cc");
1049 EXPECT_EQ(results4[3], "dd");
1050
1051 std::string s5 = "aa\\";
1052 auto results5 = split(s5, "\\");
1053 EXPECT_EQ(results5[0], "aa");
Manojkiran Eda3ca40452021-10-04 22:51:37 +05301054}
Gilbert Chen6c7fed42022-02-22 15:40:17 +00001055
1056TEST(ValidEID, allTestCases)
1057{
1058 auto rc = isValidEID(MCTP_ADDR_NULL);
1059 EXPECT_EQ(rc, false);
1060 rc = isValidEID(MCTP_ADDR_ANY);
1061 EXPECT_EQ(rc, false);
1062 rc = isValidEID(1);
1063 EXPECT_EQ(rc, false);
1064 rc = isValidEID(2);
1065 EXPECT_EQ(rc, false);
1066 rc = isValidEID(3);
1067 EXPECT_EQ(rc, false);
1068 rc = isValidEID(4);
1069 EXPECT_EQ(rc, false);
1070 rc = isValidEID(5);
1071 EXPECT_EQ(rc, false);
1072 rc = isValidEID(6);
1073 EXPECT_EQ(rc, false);
1074 rc = isValidEID(7);
1075 EXPECT_EQ(rc, false);
1076 rc = isValidEID(MCTP_START_VALID_EID);
1077 EXPECT_EQ(rc, true);
1078 rc = isValidEID(254);
1079 EXPECT_EQ(rc, true);
1080}
Thu Nguyenb8cf46b2024-06-15 02:44:35 +00001081
1082TEST(TrimNameForDbus, goodTest)
1083{
1084 std::string name = "Name with space";
1085 std::string_view expectedName = "Name_with__space";
1086 std::string_view result = trimNameForDbus(name);
1087 EXPECT_EQ(expectedName, result);
1088 name = "Name 1\0";
1089 expectedName = "Name_1";
1090 result = trimNameForDbus(name);
1091 EXPECT_EQ(expectedName, result);
1092}