blob: 8d57ff9d2c30131cf82692a68b2a5f8d3f8927db [file] [log] [blame]
Václav Kubernát73109382018-09-14 19:52:03 +02001/*
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áta33cf082019-03-28 11:55:57 +01009#include "trompeloeil_doctest.h"
Václav Kubernát73109382018-09-14 19:52:03 +020010
Václav Kubernátc31bd602019-03-07 11:44:48 +010011#ifdef sysrepo_BACKEND
Václav Kubernát73109382018-09-14 19:52:03 +020012#include "sysrepo_access.hpp"
Václav Kubernátc31bd602019-03-07 11:44:48 +010013#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át73109382018-09-14 19:52:03 +020019#include "sysrepo_subscription.hpp"
Václav Kubernát73109382018-09-14 19:52:03 +020020
Václav Kubernátbf083ec2019-02-19 13:58:09 +010021class MockRecorder : public Recorder {
Václav Kubernát73109382018-09-14 19:52:03 +020022public:
23 MAKE_MOCK3(write, void(const std::string&, const std::string&, const std::string&), override);
24};
25
26TEST_CASE("setting values")
27{
Václav Kubernát73109382018-09-14 19:52:03 +020028 trompeloeil::sequence seq1;
29 MockRecorder mock;
30 SysrepoSubscription subscription(&mock);
Václav Kubernátc31bd602019-03-07 11:44:48 +010031
32#ifdef sysrepo_BACKEND
Václav Kubernát73109382018-09-14 19:52:03 +020033 SysrepoAccess datastore("netconf-cli-test");
Václav Kubernátc31bd602019-03-07 11:44:48 +010034#elif defined(netconf_BACKEND)
35 NetconfAccess datastore(NETOPEER_SOCKET_PATH);
36#else
37#error "Unknown backend"
38#endif
Václav Kubernát73109382018-09-14 19:52:03 +020039
Václav Kubernát134d78f2019-09-03 16:42:29 +020040 SECTION("set leafInt8 to -128")
Václav Kubernát73109382018-09-14 19:52:03 +020041 {
Václav Kubernát134d78f2019-09-03 16:42:29 +020042 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át73109382018-09-14 19:52:03 +020093 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át45f4a822019-05-29 21:10:50 +0200117 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át73109382018-09-14 19:52:03 +0200125 waitForCompletionAndBitMore(seq1);
126}