Mercurial > hg > orthanc-stone
comparison UnitTestsSources/TestCommands.cpp @ 307:be2660b6e40a am-callable-and-promise
wip: commands + status update
author | am@osimis.io |
---|---|
date | Tue, 25 Sep 2018 15:14:53 +0200 |
parents | b04b13810540 |
children | b70e9be013e4 |
comparison
equal
deleted
inserted
replaced
304:6c22e0506587 | 307:be2660b6e40a |
---|---|
1 /** | 1 ///** |
2 * Stone of Orthanc | 2 // * Stone of Orthanc |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 3 // * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 // * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | 5 // * Copyright (C) 2017-2018 Osimis S.A., Belgium |
6 * | 6 // * |
7 * This program is free software: you can redistribute it and/or | 7 // * This program is free software: you can redistribute it and/or |
8 * modify it under the terms of the GNU Affero General Public License | 8 // * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | 9 // * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | 10 // * the License, or (at your option) any later version. |
11 * | 11 // * |
12 * This program is distributed in the hope that it will be useful, but | 12 // * This program is distributed in the hope that it will be useful, but |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | 13 // * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | 15 // * Affero General Public License for more details. |
16 * | 16 // * |
17 * You should have received a copy of the GNU Affero General Public License | 17 // * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 // * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 // **/ |
20 | 20 |
21 | 21 |
22 #include "gtest/gtest.h" | 22 //#include "gtest/gtest.h" |
23 | 23 |
24 #include "../Applications/Commands/BaseCommandFactory.h" | 24 //#include "../Applications/Commands/BaseCommandFactory.h" |
25 #include "Core/OrthancException.h" | 25 //#include "Core/OrthancException.h" |
26 | 26 |
27 class CommandIncrement: public OrthancStone::BaseCommand<CommandIncrement> | 27 //class CommandIncrement: public OrthancStone::BaseCommand<CommandIncrement> |
28 { | 28 //{ |
29 public: | 29 //public: |
30 static int counter; | 30 // static int counter; |
31 int increment_; | 31 // int increment_; |
32 public: | 32 //public: |
33 CommandIncrement() | 33 // CommandIncrement() |
34 : OrthancStone::BaseCommand<CommandIncrement>("increment"), | 34 // : OrthancStone::BaseCommand<CommandIncrement>("increment"), |
35 increment_(0) | 35 // increment_(0) |
36 {} | 36 // {} |
37 | 37 |
38 virtual void Execute() | 38 // virtual void Execute() |
39 { | 39 // { |
40 counter += increment_; | 40 // counter += increment_; |
41 } | 41 // } |
42 virtual void Configure(const Json::Value& arguments) | 42 // virtual void Configure(const Json::Value& arguments) |
43 { | 43 // { |
44 increment_ = arguments["increment"].asInt(); | 44 // increment_ = arguments["increment"].asInt(); |
45 } | 45 // } |
46 }; | 46 //}; |
47 | 47 |
48 // COMMAND("name", "arg1", "int", "arg2", "string") | 48 //// COMMAND("name", "arg1", "int", "arg2", "string") |
49 // COMMAND(name, arg1, arg2) | 49 //// COMMAND(name, arg1, arg2) |
50 | 50 |
51 | 51 |
52 int CommandIncrement::counter = 0; | 52 //int CommandIncrement::counter = 0; |
53 | 53 |
54 TEST(Commands, CreateNoop) | 54 //TEST(Commands, CreateNoop) |
55 { | 55 //{ |
56 OrthancStone::BaseCommandFactory factory; | 56 // OrthancStone::BaseCommandFactory factory; |
57 | 57 |
58 factory.RegisterCommandClass<OrthancStone::NoopCommand>(); | 58 // factory.RegisterCommandClass<OrthancStone::NoopCommand>(); |
59 | 59 |
60 Json::Value cmdJson; | 60 // Json::Value cmdJson; |
61 cmdJson["command"] = "noop"; | 61 // cmdJson["command"] = "noop"; |
62 | 62 |
63 std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)); | 63 // std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)); |
64 | 64 |
65 ASSERT_TRUE(command.get() != NULL); | 65 // ASSERT_TRUE(command.get() != NULL); |
66 ASSERT_EQ("noop", command->GetName()); | 66 // ASSERT_EQ("noop", command->GetName()); |
67 } | 67 //} |
68 | 68 |
69 TEST(Commands, Execute) | 69 //TEST(Commands, Execute) |
70 { | 70 //{ |
71 OrthancStone::BaseCommandFactory factory; | 71 // OrthancStone::BaseCommandFactory factory; |
72 | 72 |
73 factory.RegisterCommandClass<OrthancStone::NoopCommand>(); | 73 // factory.RegisterCommandClass<OrthancStone::NoopCommand>(); |
74 factory.RegisterCommandClass<CommandIncrement>(); | 74 // factory.RegisterCommandClass<CommandIncrement>(); |
75 | 75 |
76 Json::Value cmdJson; | 76 // Json::Value cmdJson; |
77 cmdJson["command"] = "increment"; | 77 // cmdJson["command"] = "increment"; |
78 cmdJson["args"]["increment"] = 2; | 78 // cmdJson["args"]["increment"] = 2; |
79 | 79 |
80 std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)); | 80 // std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)); |
81 | 81 |
82 ASSERT_TRUE(command.get() != NULL); | 82 // ASSERT_TRUE(command.get() != NULL); |
83 CommandIncrement::counter = 0; | 83 // CommandIncrement::counter = 0; |
84 command->Execute(); | 84 // command->Execute(); |
85 ASSERT_EQ(2, CommandIncrement::counter); | 85 // ASSERT_EQ(2, CommandIncrement::counter); |
86 } | 86 //} |
87 | 87 |
88 TEST(Commands, TryCreateUnknowCommand) | 88 //TEST(Commands, TryCreateUnknowCommand) |
89 { | 89 //{ |
90 OrthancStone::BaseCommandFactory factory; | 90 // OrthancStone::BaseCommandFactory factory; |
91 factory.RegisterCommandClass<OrthancStone::NoopCommand>(); | 91 // factory.RegisterCommandClass<OrthancStone::NoopCommand>(); |
92 | 92 |
93 Json::Value cmdJson; | 93 // Json::Value cmdJson; |
94 cmdJson["command"] = "unknown"; | 94 // cmdJson["command"] = "unknown"; |
95 | 95 |
96 ASSERT_THROW(std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)), Orthanc::OrthancException); | 96 // ASSERT_THROW(std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)), Orthanc::OrthancException); |
97 } | 97 //} |
98 | 98 |
99 TEST(Commands, TryCreateCommandFromInvalidJson) | 99 //TEST(Commands, TryCreateCommandFromInvalidJson) |
100 { | 100 //{ |
101 OrthancStone::BaseCommandFactory factory; | 101 // OrthancStone::BaseCommandFactory factory; |
102 factory.RegisterCommandClass<OrthancStone::NoopCommand>(); | 102 // factory.RegisterCommandClass<OrthancStone::NoopCommand>(); |
103 | 103 |
104 Json::Value cmdJson; | 104 // Json::Value cmdJson; |
105 cmdJson["command-name"] = "noop"; | 105 // cmdJson["command-name"] = "noop"; |
106 | 106 |
107 ASSERT_THROW(std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)), Orthanc::OrthancException); | 107 // ASSERT_THROW(std::auto_ptr<OrthancStone::ICommand> command(factory.CreateFromJson(cmdJson)), Orthanc::OrthancException); |
108 } | 108 //} |