@@ -509,6 +509,32 @@ TEST_F(Lease4Test, fromElement) {
509
509
EXPECT_EQ (" { \" foo\" : \" bar\" }" , lease->getContext ()->str ());
510
510
}
511
511
512
+ // Verify that a released Lease4 can be created from JSON.
513
+ TEST_F (Lease4Test, fromElementReleased) {
514
+ // Same as fromElement test at the exception of the state.
515
+ std::string json = " {"
516
+ " \" client-id\" : \" 17:34:e2:ff:09:92:54\" ,"
517
+ " \" cltt\" : 12345678,"
518
+ " \" fqdn-fwd\" : true,"
519
+ " \" fqdn-rev\" : true,"
520
+ " \" hostname\" : \" urania.example.ORG\" ,"
521
+ " \" hw-address\" : \" 08:00:2b:02:3f:4e\" ,"
522
+ " \" ip-address\" : \" 192.0.2.3\" ,"
523
+ " \" state\" : 3,"
524
+ " \" subnet-id\" : 789,"
525
+ " \" pool-id\" : 5,"
526
+ " \" user-context\" : { \" foo\" : \" bar\" },"
527
+ " \" valid-lft\" : 3600 "
528
+ " }" ;
529
+
530
+ Lease4Ptr lease;
531
+ ASSERT_NO_THROW (lease = Lease4::fromElement (Element::fromJSON (json)));
532
+
533
+ ASSERT_TRUE (lease);
534
+
535
+ EXPECT_EQ (Lease::STATE_RELEASED, lease->state_ );
536
+ }
537
+
512
538
// Test that specifying invalid values for a lease or not specifying
513
539
// mandatory lease parameters causes an error while parsing the lease.
514
540
TEST_F (Lease4Test, fromElementInvalidValues) {
@@ -590,6 +616,7 @@ TEST_F(Lease4Test, stateToText) {
590
616
EXPECT_EQ (" declined" , Lease4::statesToText (Lease::STATE_DECLINED));
591
617
EXPECT_EQ (" expired-reclaimed" , Lease4::statesToText (Lease::STATE_EXPIRED_RECLAIMED));
592
618
EXPECT_EQ (" released" , Lease4::statesToText (Lease::STATE_RELEASED));
619
+ EXPECT_EQ (" unknown (4)" , Lease4::statesToText (4 ));
593
620
}
594
621
595
622
// / @brief Creates an instance of the lease with certain FQDN data.
@@ -1299,6 +1326,35 @@ TEST(Lease6Test, fromElementPD) {
1299
1326
EXPECT_EQ (400 , lease->preferred_lft_ );
1300
1327
}
1301
1328
1329
+ // Verify that a released Lease6 can be created from JSON.
1330
+ TEST (Lease6Test, fromElementReleased) {
1331
+ // Same as fromElementNA test at the exception of the state.
1332
+ std::string json = " {"
1333
+ " \" cltt\" : 12345678,"
1334
+ " \" duid\" : \" 00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f\" ,"
1335
+ " \" fqdn-fwd\" : false,"
1336
+ " \" fqdn-rev\" : false,"
1337
+ " \" hostname\" : \" urania.EXAMPLE.org\" ,"
1338
+ " \" hw-address\" : \" 08:00:2b:02:3f:4e\" ,"
1339
+ " \" iaid\" : 123456,"
1340
+ " \" ip-address\" : \" 2001:db8::1\" ,"
1341
+ " \" preferred-lft\" : 400,"
1342
+ " \" state\" : 3,"
1343
+ " \" subnet-id\" : 5678,"
1344
+ " \" pool-id\" : 5,"
1345
+ " \" type\" : \" IA_NA\" ,"
1346
+ " \" user-context\" : { \" foobar\" : 1234 },"
1347
+ " \" valid-lft\" : 800"
1348
+ " }" ;
1349
+
1350
+ Lease6Ptr lease;
1351
+ ASSERT_NO_THROW (lease = Lease6::fromElement (Element::fromJSON (json)));
1352
+
1353
+ ASSERT_TRUE (lease);
1354
+
1355
+ EXPECT_EQ (Lease::STATE_RELEASED, lease->state_ );
1356
+ }
1357
+
1302
1358
// Test that specifying invalid values for a lease or not specifying
1303
1359
// mandatory lease parameters causes an error while parsing the lease.
1304
1360
TEST (Lease6Test, fromElementInvalidValues) {
@@ -1365,6 +1421,7 @@ TEST(Lease6Test, stateToText) {
1365
1421
EXPECT_EQ (" declined" , Lease6::statesToText (Lease::STATE_DECLINED));
1366
1422
EXPECT_EQ (" expired-reclaimed" , Lease6::statesToText (Lease::STATE_EXPIRED_RECLAIMED));
1367
1423
EXPECT_EQ (" released" , Lease6::statesToText (Lease::STATE_RELEASED));
1424
+ EXPECT_EQ (" unknown (4)" , Lease6::statesToText (4 ));
1368
1425
}
1369
1426
1370
1427
} // end of anonymous namespace
0 commit comments