Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.h" |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 10 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 11 | #ifdef sysrepo_BACKEND |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 12 | #include "sysrepo_access.hpp" |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 13 | #elif defined(netconf_BACKEND) |
| 14 | #include "netconf_access.hpp" |
| 15 | #include "netopeer_vars.hpp" |
| 16 | #else |
| 17 | #error "Unknown backend" |
| 18 | #endif |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 19 | #include "sysrepo_subscription.hpp" |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 20 | |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 21 | class MockRecorder : public Recorder { |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 22 | public: |
| 23 | MAKE_MOCK3(write, void(const std::string&, const std::string&, const std::string&), override); |
| 24 | }; |
| 25 | |
| 26 | TEST_CASE("setting values") |
| 27 | { |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 28 | trompeloeil::sequence seq1; |
| 29 | MockRecorder mock; |
| 30 | SysrepoSubscription subscription(&mock); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 31 | |
| 32 | #ifdef sysrepo_BACKEND |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 33 | SysrepoAccess datastore("netconf-cli-test"); |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 34 | #elif defined(netconf_BACKEND) |
| 35 | NetconfAccess datastore(NETOPEER_SOCKET_PATH); |
| 36 | #else |
| 37 | #error "Unknown backend" |
| 38 | #endif |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 39 | |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame^] | 40 | SECTION("set leafInt8 to -128") |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 41 | { |
Václav Kubernát | 134d78f | 2019-09-03 16:42:29 +0200 | [diff] [blame^] | 42 | REQUIRE_CALL(mock, write("/example-schema:leafInt8", "", "-128")); |
| 43 | datastore.setLeaf("/example-schema:leafInt8", int8_t{-128}); |
| 44 | datastore.commitChanges(); |
| 45 | } |
| 46 | |
| 47 | SECTION("set leafInt16 to -32768") |
| 48 | { |
| 49 | REQUIRE_CALL(mock, write("/example-schema:leafInt16", "", "-32768")); |
| 50 | datastore.setLeaf("/example-schema:leafInt16", int16_t{-32768}); |
| 51 | datastore.commitChanges(); |
| 52 | } |
| 53 | |
| 54 | SECTION("set leafInt32 to -2147483648") |
| 55 | { |
| 56 | REQUIRE_CALL(mock, write("/example-schema:leafInt32", "", "-2147483648")); |
| 57 | datastore.setLeaf("/example-schema:leafInt32", int32_t{-2147483648}); |
| 58 | datastore.commitChanges(); |
| 59 | } |
| 60 | |
| 61 | SECTION("set leafInt64 to -50000000000") |
| 62 | { |
| 63 | REQUIRE_CALL(mock, write("/example-schema:leafInt64", "", "-50000000000")); |
| 64 | datastore.setLeaf("/example-schema:leafInt64", int64_t{-50000000000}); |
| 65 | datastore.commitChanges(); |
| 66 | } |
| 67 | |
| 68 | SECTION("set leafUInt8 to 255") |
| 69 | { |
| 70 | REQUIRE_CALL(mock, write("/example-schema:leafUInt8", "", "255")); |
| 71 | datastore.setLeaf("/example-schema:leafUInt8", uint8_t{255}); |
| 72 | datastore.commitChanges(); |
| 73 | } |
| 74 | |
| 75 | SECTION("set leafUInt16 to 65535") |
| 76 | { |
| 77 | REQUIRE_CALL(mock, write("/example-schema:leafUInt16", "", "65535")); |
| 78 | datastore.setLeaf("/example-schema:leafUInt16", uint16_t{65535}); |
| 79 | datastore.commitChanges(); |
| 80 | } |
| 81 | |
| 82 | SECTION("set leafUInt32 to 4294967295") |
| 83 | { |
| 84 | REQUIRE_CALL(mock, write("/example-schema:leafUInt32", "", "4294967295")); |
| 85 | datastore.setLeaf("/example-schema:leafUInt32", uint32_t{4294967295}); |
| 86 | datastore.commitChanges(); |
| 87 | } |
| 88 | |
| 89 | SECTION("set leafUInt64 to 50000000000") |
| 90 | { |
| 91 | REQUIRE_CALL(mock, write("/example-schema:leafUInt64", "", "50000000000")); |
| 92 | datastore.setLeaf("/example-schema:leafUInt64", uint64_t{50000000000}); |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 93 | datastore.commitChanges(); |
| 94 | } |
| 95 | |
| 96 | SECTION("set leafEnum to coze") |
| 97 | { |
| 98 | REQUIRE_CALL(mock, write("/example-schema:leafEnum", "", "coze")); |
| 99 | datastore.setLeaf("/example-schema:leafEnum", enum_{"coze"}); |
| 100 | datastore.commitChanges(); |
| 101 | } |
| 102 | |
| 103 | SECTION("set leafDecimal to 123.544") |
| 104 | { |
| 105 | REQUIRE_CALL(mock, write("/example-schema:leafDecimal", "", "123.544")); |
| 106 | datastore.setLeaf("/example-schema:leafDecimal", 123.544); |
| 107 | datastore.commitChanges(); |
| 108 | } |
| 109 | |
| 110 | SECTION("create presence container") |
| 111 | { |
| 112 | REQUIRE_CALL(mock, write("/example-schema:pContainer", "", "")); |
| 113 | datastore.createPresenceContainer("/example-schema:pContainer"); |
| 114 | datastore.commitChanges(); |
| 115 | } |
| 116 | |
Václav Kubernát | 45f4a82 | 2019-05-29 21:10:50 +0200 | [diff] [blame] | 117 | SECTION("create a list instance") |
| 118 | { |
| 119 | REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']", "", "")); |
| 120 | REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']/name", "", "Nguyen")); |
| 121 | datastore.createListInstance("/example-schema:person[name='Nguyen']"); |
| 122 | datastore.commitChanges(); |
| 123 | } |
| 124 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 125 | waitForCompletionAndBitMore(seq1); |
| 126 | } |