annotate OrthancFramework/UnitTestsSources/JobsTests.cpp @ 4805:0a38000b086d

Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
author Alain Mazy <am@osimis.io>
date Tue, 09 Nov 2021 09:51:14 +0100
parents 4f368230f32b
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1681
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
20 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
21
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
22
4060
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
24 // Must be the first to be sure to use the Orthanc framework shared library
4060
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
25 # include <OrthancFramework.h>
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
26 #endif
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
27
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4060
diff changeset
28 #include <gtest/gtest.h>
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
30 #include "../../OrthancFramework/Sources/Compatibility.h"
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
31 #include "../../OrthancFramework/Sources/DicomNetworking/DicomAssociationParameters.h"
4060
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
32 #include "../../OrthancFramework/Sources/DicomNetworking/RemoteModalityParameters.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
33 #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
35 #include "../../OrthancFramework/Sources/JobsEngine/GenericJobUnserializer.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
36 #include "../../OrthancFramework/Sources/JobsEngine/JobsEngine.h"
4060
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 #include "../../OrthancFramework/Sources/JobsEngine/Operations/JobOperationValues.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
38 #include "../../OrthancFramework/Sources/JobsEngine/Operations/LogJobOperation.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
39 #include "../../OrthancFramework/Sources/JobsEngine/Operations/NullOperationValue.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
40 #include "../../OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
41 #include "../../OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h"
149172a06b4d splitting MultiThreadingTests.cpp into JobsTests.cpp and ServerJobsTests.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
42 #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
43 #include "../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
44 #include "../../OrthancFramework/Sources/MultiThreading/SharedMessageQueue.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
45 #include "../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
46 #include "../../OrthancFramework/Sources/SerializationToolbox.h"
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
47
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 using namespace Orthanc;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 namespace
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
53 class DummyJob : public IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
54 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
55 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
56 bool fails_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
57 unsigned int count_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
58 unsigned int steps_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
59
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
60 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
61 DummyJob() :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
62 fails_(false),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
63 count_(0),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
64 steps_(4)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
65 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
66 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
67
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
68 explicit DummyJob(bool fails) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
69 fails_(fails),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
70 count_(0),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
71 steps_(4)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
72 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
73 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
74
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
75 virtual void Start() ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
76 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
77 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
78
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
79 virtual void Reset() ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
80 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
81 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
82
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
83 virtual JobStepResult Step(const std::string& jobId) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
84 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
85 if (fails_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
86 {
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
87 return JobStepResult::Failure(ErrorCode_ParameterOutOfRange, NULL);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
88 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
89 else if (count_ == steps_ - 1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
90 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
91 return JobStepResult::Success();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
92 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
93 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
94 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
95 count_++;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
96 return JobStepResult::Continue();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
97 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
98 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
99
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
100 virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
101 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
102 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
103
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
104 virtual float GetProgress() ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
105 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
106 return static_cast<float>(count_) / static_cast<float>(steps_ - 1);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
107 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
108
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
109 virtual void GetJobType(std::string& type) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
110 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
111 type = "DummyJob";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
112 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
113
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
114 virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
115 {
2667
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
116 value = Json::objectValue;
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
117 value["Type"] = "DummyJob";
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
118 return true;
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
119 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
120
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
121 virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
122 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
123 value["hello"] = "world";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
124 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
125
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
126 virtual bool GetOutput(std::string& output,
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
127 MimeType& mime,
4805
0a38000b086d Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents: 4779
diff changeset
128 std::string& filename,
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
129 const std::string& key) ORTHANC_OVERRIDE
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
130 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
131 return false;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
132 }
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
133 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
134
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
135
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
136 class DummyInstancesJob : public SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
137 {
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
138 private:
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
139 bool trailingStepDone_;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
140
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
141 protected:
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
142 virtual bool HandleInstance(const std::string& instance) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
143 {
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
144 return (instance != "nope");
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
145 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
146
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
147 virtual bool HandleTrailingStep() ORTHANC_OVERRIDE
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
148 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
149 if (HasTrailingStep())
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
150 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
151 if (trailingStepDone_)
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
152 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
153 throw OrthancException(ErrorCode_InternalError);
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
154 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
155 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
156 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
157 trailingStepDone_ = true;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
158 return true;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
159 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
160 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
161 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
162 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
163 throw OrthancException(ErrorCode_InternalError);
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
164 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
165 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
166
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
167 public:
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
168 DummyInstancesJob() :
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
169 trailingStepDone_(false)
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
170 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
171 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
172
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
173 explicit DummyInstancesJob(const Json::Value& value) :
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
174 SetOfInstancesJob(value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
175 {
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
176 if (HasTrailingStep())
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
177 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
178 trailingStepDone_ = (GetPosition() == GetCommandsCount());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
179 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
180 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
181 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
182 trailingStepDone_ = false;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
183 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
184 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
185
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
186 bool IsTrailingStepDone() const
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
187 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
188 return trailingStepDone_;
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
189 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
190
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
191 virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
192 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
193 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
194
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
195 virtual void GetJobType(std::string& s) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
196 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
197 s = "DummyInstancesJob";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
198 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
199 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
200
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
201
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
202 class DummyUnserializer : public GenericJobUnserializer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
203 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
204 public:
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2872
diff changeset
205 virtual IJob* UnserializeJob(const Json::Value& value) ORTHANC_OVERRIDE
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
206 {
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
207 if (SerializationToolbox::ReadString(value, "Type") == "DummyInstancesJob")
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
208 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
209 return new DummyInstancesJob(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
210 }
2667
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
211 else if (SerializationToolbox::ReadString(value, "Type") == "DummyJob")
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
212 {
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
213 return new DummyJob;
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
214 }
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
215 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
216 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
217 return GenericJobUnserializer::UnserializeJob(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
218 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
219 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
220 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
221
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
222
1396
ac4efabeb80c Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
223 class DynamicInteger : public IDynamicObject
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 int value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 std::set<int>& target_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 DynamicInteger(int value, std::set<int>& target) :
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 value_(value), target_(target)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 int GetValue() const
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 return value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 };
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 TEST(MultiThreading, SharedMessageQueueBasic)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 q.Enqueue(new DynamicInteger(30, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 q.Enqueue(new DynamicInteger(40, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
255 std::unique_ptr<DynamicInteger> i;
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 ASSERT_EQ(NULL, q.Dequeue(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 TEST(MultiThreading, SharedMessageQueueClean)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 try
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 q.Enqueue(new DynamicInteger(20, s));
1583
9ea3d082b064 got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
275 throw OrthancException(ErrorCode_InternalError);
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 catch (OrthancException&)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
283
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
284
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
285 static bool CheckState(JobsRegistry& registry,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
286 const std::string& id,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
287 JobState state)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
288 {
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
289 JobState s;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
290 if (registry.GetState(s, id))
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
291 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
292 return state == s;
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
293 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
294 else
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
295 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
296 return false;
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
297 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
298 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
299
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
300
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
301 static bool CheckErrorCode(JobsRegistry& registry,
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
302 const std::string& id,
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
303 ErrorCode code)
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
304 {
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
305 JobInfo s;
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
306 if (registry.GetJobInfo(s, id))
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
307 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
308 return code == s.GetStatus().GetErrorCode();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
309 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
310 else
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
311 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
312 return false;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
313 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
314 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
315
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
316
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
317 TEST(JobsRegistry, Priority)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
318 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
319 JobsRegistry registry(10);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
320
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
321 std::string i1, i2, i3, i4;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
322 registry.Submit(i1, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
323 registry.Submit(i2, new DummyJob(), 30);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
324 registry.Submit(i3, new DummyJob(), 20);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
325 registry.Submit(i4, new DummyJob(), 5);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
326
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
327 registry.SetMaxCompletedJobs(2);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
328
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
329 std::set<std::string> id;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
330 registry.ListJobs(id);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
331
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
332 ASSERT_EQ(4u, id.size());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
333 ASSERT_TRUE(id.find(i1) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
334 ASSERT_TRUE(id.find(i2) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
335 ASSERT_TRUE(id.find(i3) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
336 ASSERT_TRUE(id.find(i4) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
337
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
338 ASSERT_TRUE(CheckState(registry, i2, JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
339
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
340 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
341 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
342 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
343 ASSERT_EQ(30, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
344 ASSERT_EQ(i2, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
345
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
346 ASSERT_TRUE(CheckState(registry, i2, JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
347 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
348
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
349 ASSERT_TRUE(CheckState(registry, i2, JobState_Failure));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
350 ASSERT_TRUE(CheckState(registry, i3, JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
351
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
352 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
353 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
354 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
355 ASSERT_EQ(20, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
356 ASSERT_EQ(i3, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
357
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
358 job.MarkSuccess();
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
359
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
360 ASSERT_TRUE(CheckState(registry, i3, JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
361 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
362
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
363 ASSERT_TRUE(CheckState(registry, i3, JobState_Success));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
364
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
365 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
366 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
367 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
368 ASSERT_EQ(10, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
369 ASSERT_EQ(i1, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
370 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
371
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
372 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
373 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
374 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
375 ASSERT_EQ(5, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
376 ASSERT_EQ(i4, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
377 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
378
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
379 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
380 JobsRegistry::RunningJob job(registry, 1);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
381 ASSERT_FALSE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
382 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
383
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
384 JobState s;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
385 ASSERT_TRUE(registry.GetState(s, i1));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
386 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
387 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
388 ASSERT_TRUE(registry.GetState(s, i4));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
389
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
390 registry.SetMaxCompletedJobs(1); // (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
391 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
392 ASSERT_TRUE(registry.GetState(s, i4));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
393 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
394
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
395
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
396 TEST(JobsRegistry, Simultaneous)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
397 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
398 JobsRegistry registry(10);
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
399
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
400 std::string i1, i2;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
401 registry.Submit(i1, new DummyJob(), 20);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
402 registry.Submit(i2, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
403
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
404 ASSERT_TRUE(CheckState(registry, i1, JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
405 ASSERT_TRUE(CheckState(registry, i2, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
406
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
407 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
408 JobsRegistry::RunningJob job1(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
409 JobsRegistry::RunningJob job2(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
410
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
411 ASSERT_TRUE(job1.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
412 ASSERT_TRUE(job2.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
414 job1.MarkFailure();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
415 job2.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
416
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
417 ASSERT_TRUE(CheckState(registry, i1, JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
418 ASSERT_TRUE(CheckState(registry, i2, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
419 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
420
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
421 ASSERT_TRUE(CheckState(registry, i1, JobState_Failure));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
422 ASSERT_TRUE(CheckState(registry, i2, JobState_Success));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
423 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
424
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
425
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
426 TEST(JobsRegistry, Resubmit)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
427 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
428 JobsRegistry registry(10);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
429
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
430 std::string id;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
431 registry.Submit(id, new DummyJob(), 10);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
432
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
433 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
434
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
435 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
436 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
437
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
438 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
439 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
440 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
441 job.MarkFailure();
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
442
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
443 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
444
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
445 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
446 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
447 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
448
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
449 ASSERT_TRUE(CheckState(registry, id, JobState_Failure));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
450
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
451 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
452 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
453
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
454 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
455 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
456 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
457 ASSERT_EQ(id, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
458
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
459 job.MarkSuccess();
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
460 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
461 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
462
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
463 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
464
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
465 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
466 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
467 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
468
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
469
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
470 TEST(JobsRegistry, Retry)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
471 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
472 JobsRegistry registry(10);
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
473
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
474 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
475 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
476
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
477 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
478
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
479 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
480 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
481 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
482 job.MarkRetry(0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
483
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
484 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
485 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
486
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
487 ASSERT_TRUE(CheckState(registry, id, JobState_Retry));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
488
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
489 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
490 ASSERT_TRUE(CheckState(registry, id, JobState_Retry));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
492 registry.ScheduleRetries();
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
493 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
494
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
495 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
496 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
497 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
498 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
499
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
500 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
501 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
502
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
503 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
504 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
505
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
506
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
507 TEST(JobsRegistry, PausePending)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
508 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
509 JobsRegistry registry(10);
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
510
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
511 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
512 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
513
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
514 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
515
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
516 registry.Pause(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
517 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
518
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
519 registry.Pause(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
520 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
521
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
522 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
523 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
524
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
525 registry.Resume(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
526 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
527 }
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
528
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
529
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
530 TEST(JobsRegistry, PauseRunning)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
531 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
532 JobsRegistry registry(10);
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
533
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
534 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
535 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
536
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
537 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
538
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
539 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
540 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
541 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
542
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
543 registry.Resubmit(id);
2562
1e66fe3ddf9f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2559
diff changeset
544 job.MarkPause();
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
545 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
546 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
547
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
548 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
549
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
550 registry.Resubmit(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
551 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
552
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
553 registry.Resume(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
554 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
555
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
556 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
557 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
558 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
559
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
560 job.MarkSuccess();
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
561 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
562 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
563
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
564 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
565 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
566
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
568 TEST(JobsRegistry, PauseRetry)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
569 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
570 JobsRegistry registry(10);
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
571
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
572 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
573 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
574
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
575 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
576
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
577 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
578 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
579 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
580
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
581 job.MarkRetry(0);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
582 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
583 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
584
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
585 ASSERT_TRUE(CheckState(registry, id, JobState_Retry));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
586
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
587 registry.Pause(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
588 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
589
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
590 registry.Resume(id);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
591 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
592
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
593 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
594 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
595 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
596
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
597 job.MarkSuccess();
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
598 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
599 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
600
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
601 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
602 }
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
603
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
604
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
605 TEST(JobsRegistry, Cancel)
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
606 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
607 JobsRegistry registry(10);
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
608
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
609 std::string id;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
610 registry.Submit(id, new DummyJob(), 10);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
611
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
612 ASSERT_FALSE(registry.Cancel("nope"));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
613
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
614 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
615 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
616
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
617 ASSERT_TRUE(registry.Cancel(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
618 ASSERT_TRUE(CheckState(registry, id, JobState_Failure));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
619 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
620
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
621 ASSERT_TRUE(registry.Cancel(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
622 ASSERT_TRUE(CheckState(registry, id, JobState_Failure));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
623 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
624
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
625 ASSERT_TRUE(registry.Resubmit(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
626 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
627 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
628
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
629 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
630 JobsRegistry::RunningJob job(registry, 0);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
631 ASSERT_TRUE(job.IsValid());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
632
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
633 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
634
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
635 job.MarkSuccess();
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
636 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
637 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
638
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
639 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
640 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
641
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
642 ASSERT_TRUE(registry.Cancel(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
643 ASSERT_TRUE(CheckState(registry, id, JobState_Success));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
644 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
645
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
646 registry.Submit(id, new DummyJob(), 10);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
647
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
648 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
649 JobsRegistry::RunningJob job(registry, 0);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
650 ASSERT_TRUE(job.IsValid());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
651 ASSERT_EQ(id, job.GetId());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
652
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
653 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
654 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
655
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
656 job.MarkCanceled();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
657 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
658
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
659 ASSERT_TRUE(CheckState(registry, id, JobState_Failure));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
660 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
661
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
662 ASSERT_TRUE(registry.Resubmit(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
663 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
664 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
665
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
666 ASSERT_TRUE(registry.Pause(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
667 ASSERT_TRUE(CheckState(registry, id, JobState_Paused));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
668 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
669
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
670 ASSERT_TRUE(registry.Cancel(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
671 ASSERT_TRUE(CheckState(registry, id, JobState_Failure));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
672 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
673
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
674 ASSERT_TRUE(registry.Resubmit(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
675 ASSERT_TRUE(CheckState(registry, id, JobState_Pending));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
676 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
677
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
678 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
679 JobsRegistry::RunningJob job(registry, 0);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
680 ASSERT_TRUE(job.IsValid());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
681 ASSERT_EQ(id, job.GetId());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
682
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
683 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
684 ASSERT_TRUE(CheckState(registry, id, JobState_Running));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
685
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
686 job.MarkRetry(500);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
687 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
688
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
689 ASSERT_TRUE(CheckState(registry, id, JobState_Retry));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
690 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
691
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
692 ASSERT_TRUE(registry.Cancel(id));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
693 ASSERT_TRUE(CheckState(registry, id, JobState_Failure));
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
694 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
695 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
696
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
697
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
698
2599
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
699 TEST(JobsEngine, SubmitAndWait)
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
700 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
701 JobsEngine engine(10);
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
702 engine.SetThreadSleep(10);
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
703 engine.SetWorkersCount(3);
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
704 engine.Start();
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
705
2867
251614c2edac DicomMoveScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
706 Json::Value content = Json::nullValue;
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
707 engine.GetRegistry().SubmitAndWait(content, new DummyJob(), rand() % 10);
2867
251614c2edac DicomMoveScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
708 ASSERT_EQ(Json::objectValue, content.type());
251614c2edac DicomMoveScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
709 ASSERT_EQ("world", content["hello"].asString());
251614c2edac DicomMoveScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
710
251614c2edac DicomMoveScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
711 content = Json::nullValue;
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
712 ASSERT_THROW(engine.GetRegistry().SubmitAndWait(content, new DummyJob(true), rand() % 10), OrthancException);
2867
251614c2edac DicomMoveScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
713 ASSERT_EQ(Json::nullValue, content.type());
2599
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
714
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
715 engine.Stop();
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
716 }
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
717
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
718
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
719 TEST(JobsEngine, DISABLED_SequenceOfOperationsJob)
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
720 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
721 JobsEngine engine(10);
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
722 engine.SetThreadSleep(10);
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
723 engine.SetWorkersCount(3);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
724 engine.Start();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
725
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
726 std::string id;
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
727 SequenceOfOperationsJob* job = NULL;
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
728
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
729 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
730 std::unique_ptr<SequenceOfOperationsJob> a(new SequenceOfOperationsJob);
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
731 job = a.get();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
732 engine.GetRegistry().Submit(id, a.release(), 0);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
733 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
734
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
735 boost::this_thread::sleep(boost::posix_time::milliseconds(500));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
736
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
737 {
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
738 SequenceOfOperationsJob::Lock lock(*job);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
739 size_t i = lock.AddOperation(new LogJobOperation);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
740 size_t j = lock.AddOperation(new LogJobOperation);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
741 size_t k = lock.AddOperation(new LogJobOperation);
2730
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
742
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
743 StringOperationValue a("Hello");
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
744 StringOperationValue b("World");
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
745 lock.AddInput(i, a);
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
746 lock.AddInput(i, b);
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
747
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
748 lock.Connect(i, j);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
749 lock.Connect(j, k);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
750 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
751
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
752 boost::this_thread::sleep(boost::posix_time::milliseconds(2000));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
753
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
754 engine.Stop();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
755
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
756 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
757
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
758
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
759 static bool CheckSameJson(const Json::Value& a,
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
760 const Json::Value& b)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
761 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
762 std::string s = a.toStyledString();
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
763 std::string t = b.toStyledString();
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
764
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
765 if (s == t)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
766 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
767 return true;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
768 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
769 else
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
770 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
771 LOG(ERROR) << "Expected serialization: " << s;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
772 LOG(ERROR) << "Actual serialization: " << t;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
773 return false;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
774 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
775 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
776
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
777
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
778 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer,
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
779 IJob& job)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
780 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
781 Json::Value a = 42;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
782
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
783 if (!job.Serialize(a))
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
784 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
785 return false;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
786 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
787 else
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
788 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
789 std::unique_ptr<IJob> unserialized(unserializer.UnserializeJob(a));
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
790
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
791 Json::Value b = 43;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
792 if (unserialized->Serialize(b))
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
793 {
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
794 return (CheckSameJson(a, b));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
795 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
796 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
797 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
798 return false;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
799 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
800 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
801 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
802
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
803
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
804 static bool CheckIdempotentSetOfInstances(IJobUnserializer& unserializer,
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
805 SetOfInstancesJob& job)
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
806 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
807 Json::Value a = 42;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
808
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
809 if (!job.Serialize(a))
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
810 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
811 return false;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
812 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
813 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
814 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
815 std::unique_ptr<SetOfInstancesJob> unserialized
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
816 (dynamic_cast<SetOfInstancesJob*>(unserializer.UnserializeJob(a)));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
817
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
818 Json::Value b = 43;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
819 if (unserialized->Serialize(b))
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
820 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
821 return (CheckSameJson(a, b) &&
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
822 job.HasTrailingStep() == unserialized->HasTrailingStep() &&
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
823 job.GetPosition() == unserialized->GetPosition() &&
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
824 job.GetInstancesCount() == unserialized->GetInstancesCount() &&
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
825 job.GetCommandsCount() == unserialized->GetCommandsCount());
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
826 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
827 else
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
828 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
829 return false;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
830 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
831 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
832 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
833
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
834
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
835 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer,
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
836 const IJobOperationValue& value)
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
837 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
838 Json::Value a = 42;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
839 value.Serialize(a);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
840
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
841 std::unique_ptr<IJobOperationValue> unserialized(unserializer.UnserializeValue(a));
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
842
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
843 Json::Value b = 43;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
844 unserialized->Serialize(b);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
845
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
846 return CheckSameJson(a, b);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
847 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
848
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
849
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
850 TEST(JobsSerialization, BadFileFormat)
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
851 {
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
852 GenericJobUnserializer unserializer;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
853
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
854 Json::Value s;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
855
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
856 s = Json::objectValue;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
857 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
858 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
859 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
860
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
861 s = Json::arrayValue;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
862 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
863 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
864 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
865
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
866 s = "hello";
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
867 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
868 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
869 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
870
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
871 s = 42;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
872 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
873 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
874 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
875 }
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
876
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
877
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
878 TEST(JobsSerialization, JobOperationValues)
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
879 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
880 Json::Value s;
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
881
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
882 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
883 JobOperationValues values;
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
884 values.Append(new NullOperationValue);
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
885 values.Append(new StringOperationValue("hello"));
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
886 values.Append(new StringOperationValue("world"));
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
887
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
888 s = 42;
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
889 values.Serialize(s);
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
890 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
891
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
892 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
893 GenericJobUnserializer unserializer;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
894 std::unique_ptr<JobOperationValues> values(JobOperationValues::Unserialize(unserializer, s));
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
895 ASSERT_EQ(3u, values->GetSize());
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
896 ASSERT_EQ(IJobOperationValue::Type_Null, values->GetValue(0).GetType());
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
897 ASSERT_EQ(IJobOperationValue::Type_String, values->GetValue(1).GetType());
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
898 ASSERT_EQ(IJobOperationValue::Type_String, values->GetValue(2).GetType());
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
899
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
900 ASSERT_EQ("hello", dynamic_cast<const StringOperationValue&>(values->GetValue(1)).GetContent());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
901 ASSERT_EQ("world", dynamic_cast<const StringOperationValue&>(values->GetValue(2)).GetContent());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
902 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
903 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
904
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
905
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
906 TEST(JobsSerialization, GenericValues)
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
907 {
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
908 GenericJobUnserializer unserializer;
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
909 Json::Value s;
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
910
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
911 {
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
912 NullOperationValue null;
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
913
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
914 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, null));
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
915 null.Serialize(s);
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
916 }
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
917
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
918 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
919 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
920
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
921 std::unique_ptr<IJobOperationValue> value;
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
922 value.reset(unserializer.UnserializeValue(s));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
923
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
924 ASSERT_EQ(IJobOperationValue::Type_Null, value->GetType());
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
925
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
926 {
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
927 StringOperationValue str("Hello");
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
928
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
929 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, str));
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
930 str.Serialize(s);
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
931 }
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
932
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
933 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
934 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
935 value.reset(unserializer.UnserializeValue(s));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
936
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4204
diff changeset
937 ASSERT_EQ(IJobOperationValue::Type_String, value->GetType());
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
938 ASSERT_EQ("Hello", dynamic_cast<StringOperationValue&>(*value).GetContent());
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
939 }
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
940
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
941
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
942 TEST(JobsSerialization, GenericJobs)
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
943 {
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
944 Json::Value s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
945
2658
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
946 // This tests SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
947
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
948 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
949 DummyInstancesJob job;
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
950 job.SetDescription("description");
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
951 job.AddInstance("hello");
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
952 job.AddInstance("nope");
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
953 job.AddInstance("world");
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
954 job.SetPermissive(true);
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
955 ASSERT_THROW(job.Step("jobId"), OrthancException); // Not started yet
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
956 ASSERT_FALSE(job.HasTrailingStep());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
957 ASSERT_FALSE(job.IsTrailingStepDone());
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
958 job.Start();
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
959 ASSERT_EQ(JobStepCode_Continue, job.Step("jobId").GetCode());
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
960 ASSERT_EQ(JobStepCode_Continue, job.Step("jobId").GetCode());
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
961
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
962 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
963 DummyUnserializer unserializer;
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
964 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
965 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
966
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
967 ASSERT_TRUE(job.Serialize(s));
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
968 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
969
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
970 {
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
971 DummyUnserializer unserializer;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
972 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
973 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
974
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
975 std::unique_ptr<IJob> job;
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
976 job.reset(unserializer.UnserializeJob(s));
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
977
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
978 const DummyInstancesJob& tmp = dynamic_cast<const DummyInstancesJob&>(*job);
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
979 ASSERT_FALSE(tmp.IsStarted());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
980 ASSERT_TRUE(tmp.IsPermissive());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
981 ASSERT_EQ("description", tmp.GetDescription());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
982 ASSERT_EQ(3u, tmp.GetInstancesCount());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
983 ASSERT_EQ(2u, tmp.GetPosition());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
984 ASSERT_EQ(1u, tmp.GetFailedInstances().size());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
985 ASSERT_EQ("hello", tmp.GetInstance(0));
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
986 ASSERT_EQ("nope", tmp.GetInstance(1));
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
987 ASSERT_EQ("world", tmp.GetInstance(2));
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
988 ASSERT_TRUE(tmp.IsFailedInstance("nope"));
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2653
diff changeset
989 }
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
990
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
991 // SequenceOfOperationsJob
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
992
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
993 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
994 SequenceOfOperationsJob job;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
995 job.SetDescription("hello");
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
996
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
997 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
998 SequenceOfOperationsJob::Lock lock(job);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
999 size_t a = lock.AddOperation(new LogJobOperation);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1000 size_t b = lock.AddOperation(new LogJobOperation);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1001 lock.Connect(a, b);
2730
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
1002
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
1003 StringOperationValue s1("hello");
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
1004 StringOperationValue s2("world");
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
1005 lock.AddInput(a, s1);
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2726
diff changeset
1006 lock.AddInput(a, s2);
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1007 lock.SetTrailingOperationTimeout(300);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1008 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1009
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1010 ASSERT_EQ(JobStepCode_Continue, job.Step("jobId").GetCode());
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1011
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1012 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1013 GenericJobUnserializer unserializer;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1014 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, job));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1015 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1016
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1017 ASSERT_TRUE(job.Serialize(s));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1018 }
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1019
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1020 {
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1021 GenericJobUnserializer unserializer;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1022 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1023 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1024
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1025 std::unique_ptr<IJob> job;
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1026 job.reset(unserializer.UnserializeJob(s));
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1027
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1028 std::string tmp;
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1029 dynamic_cast<SequenceOfOperationsJob&>(*job).GetDescription(tmp);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1030 ASSERT_EQ("hello", tmp);
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1031 }
2658
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
1032 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
1033
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
1034
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1035 static bool IsSameTagValue(const ParsedDicomFile& dicom1,
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1036 const ParsedDicomFile& dicom2,
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1037 DicomTag tag)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1038 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1039 std::string a, b;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1040 return (dicom1.GetTagValue(a, tag) &&
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1041 dicom2.GetTagValue(b, tag) &&
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1042 (a == b));
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1043 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1044
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1045
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1046
2660
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2659
diff changeset
1047 TEST(JobsSerialization, DicomModification)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2659
diff changeset
1048 {
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1049 Json::Value s;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1050
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1051 ParsedDicomFile source(true);
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1052 source.Insert(DICOM_TAG_STUDY_DESCRIPTION, "Test 1", false, "");
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1053 source.Insert(DICOM_TAG_SERIES_DESCRIPTION, "Test 2", false, "");
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1054 source.Insert(DICOM_TAG_PATIENT_NAME, "Test 3", false, "");
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1055
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1056 std::unique_ptr<ParsedDicomFile> modified(source.Clone(true));
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1057
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1058 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1059 DicomModification modification;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1060 modification.SetLevel(ResourceType_Series);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1061 modification.Clear(DICOM_TAG_STUDY_DESCRIPTION);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1062 modification.Remove(DICOM_TAG_SERIES_DESCRIPTION);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1063 modification.Replace(DICOM_TAG_PATIENT_NAME, "Test 4", true);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1064
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1065 modification.Apply(*modified);
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
1066
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2664
diff changeset
1067 s = 42;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1068 modification.Serialize(s);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1069 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1070
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1071 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1072 DicomModification modification(s);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1073 ASSERT_EQ(ResourceType_Series, modification.GetLevel());
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1074
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1075 std::unique_ptr<ParsedDicomFile> second(source.Clone(true));
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1076 modification.Apply(*second);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1077
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1078 std::string t;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1079 ASSERT_TRUE(second->GetTagValue(t, DICOM_TAG_STUDY_DESCRIPTION));
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1080 ASSERT_TRUE(t.empty());
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1081 ASSERT_FALSE(second->GetTagValue(t, DICOM_TAG_SERIES_DESCRIPTION));
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1082 ASSERT_TRUE(second->GetTagValue(t, DICOM_TAG_PATIENT_NAME));
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1083 ASSERT_EQ("Test 4", t);
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1084
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1085 ASSERT_TRUE(IsSameTagValue(source, *modified, DICOM_TAG_STUDY_INSTANCE_UID));
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1086 ASSERT_TRUE(IsSameTagValue(source, *second, DICOM_TAG_STUDY_INSTANCE_UID));
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1087
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1088 ASSERT_FALSE(IsSameTagValue(source, *second, DICOM_TAG_SERIES_INSTANCE_UID));
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1089 ASSERT_TRUE(IsSameTagValue(*modified, *second, DICOM_TAG_SERIES_INSTANCE_UID));
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2660
diff changeset
1090 }
2660
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2659
diff changeset
1091 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2659
diff changeset
1092
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2659
diff changeset
1093
4687
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1094 TEST(JobsSerialization, DicomModification2)
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1095 {
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1096 Json::Value s;
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1097
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1098 {
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1099 DicomModification modification;
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1100 modification.SetupAnonymization(DicomVersion_2017c);
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1101 modification.Remove(DicomPath(DICOM_TAG_REFERENCED_IMAGE_SEQUENCE, 1, DICOM_TAG_SOP_INSTANCE_UID));
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1102 modification.Replace(DicomPath(DICOM_TAG_REFERENCED_IMAGE_SEQUENCE, 1, DICOM_TAG_SOP_CLASS_UID), "Hello", true);
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1103 modification.Keep(DicomPath(DICOM_TAG_REFERENCED_IMAGE_SEQUENCE, 1, DICOM_TAG_PATIENT_NAME));
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1104
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1105 s = 42;
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1106 modification.Serialize(s);
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1107 }
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1108
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1109 {
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1110 DicomModification modification(s);
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1111
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1112 // Check idempotent serialization
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1113 Json::Value ss;
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1114 modification.Serialize(ss);
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1115 ASSERT_EQ(s.toStyledString(), ss.toStyledString());
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1116 }
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1117 }
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1118
fcd2dc7c8f31 "Replace", "Keep" and "Remove" in "/modify" and "/anonymize" accept paths to subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4656
diff changeset
1119
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1120 TEST(JobsSerialization, Registry)
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
1121 {
2667
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1122 Json::Value s;
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1123 std::string i1, i2;
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1124
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1125 {
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
1126 JobsRegistry registry(10);
2667
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1127 registry.Submit(i1, new DummyJob(), 10);
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1128 registry.Submit(i2, new SequenceOfOperationsJob(), 30);
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1129 registry.Serialize(s);
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1130 }
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1131
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1132 {
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1133 DummyUnserializer unserializer;
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
1134 JobsRegistry registry(unserializer, s, 10);
2667
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1135
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1136 Json::Value t;
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1137 registry.Serialize(t);
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1138 ASSERT_TRUE(CheckSameJson(s, t));
5fa2f2ce74f0 serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1139 }
2658
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
1140 }
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1141
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1142
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1143 TEST(JobsSerialization, TrailingStep)
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1144 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1145 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1146 Json::Value s;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1147
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1148 DummyInstancesJob job;
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1149 ASSERT_EQ(0u, job.GetCommandsCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1150 ASSERT_EQ(0u, job.GetInstancesCount());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1151
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1152 job.Start();
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1153 ASSERT_EQ(0u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1154 ASSERT_FALSE(job.HasTrailingStep());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1155 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1156
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1157 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1158 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1159 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1160 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1161
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1162 ASSERT_EQ(JobStepCode_Success, job.Step("jobId").GetCode());
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1163 ASSERT_EQ(1u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1164 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1165
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1166 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1167 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1168 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1169 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1170
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1171 ASSERT_THROW(job.Step("jobId"), OrthancException);
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1172 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1173
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1174 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1175 Json::Value s;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1176
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1177 DummyInstancesJob job;
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1178 job.AddInstance("hello");
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1179 job.AddInstance("world");
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1180 ASSERT_EQ(2u, job.GetCommandsCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1181 ASSERT_EQ(2u, job.GetInstancesCount());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1182
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1183 job.Start();
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1184 ASSERT_EQ(0u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1185 ASSERT_FALSE(job.HasTrailingStep());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1186 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1187
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1188 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1189 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1190 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1191 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1192
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1193 ASSERT_EQ(JobStepCode_Continue, job.Step("jobId").GetCode());
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1194 ASSERT_EQ(1u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1195 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1196
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1197 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1198 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1199 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1200 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1201
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1202 ASSERT_EQ(JobStepCode_Success, job.Step("jobId").GetCode());
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1203 ASSERT_EQ(2u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1204 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1205
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1206 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1207 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1208 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1209 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1210
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1211 ASSERT_THROW(job.Step("jobId"), OrthancException);
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1212 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1213
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1214 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1215 Json::Value s;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1216
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1217 DummyInstancesJob job;
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1218 ASSERT_EQ(0u, job.GetInstancesCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1219 ASSERT_EQ(0u, job.GetCommandsCount());
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1220 job.AddTrailingStep();
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1221 ASSERT_EQ(0u, job.GetInstancesCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1222 ASSERT_EQ(1u, job.GetCommandsCount());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1223
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1224 job.Start(); // This adds the trailing step
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1225 ASSERT_EQ(0u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1226 ASSERT_TRUE(job.HasTrailingStep());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1227 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1228
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1229 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1230 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1231 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1232 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1233
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1234 ASSERT_EQ(JobStepCode_Success, job.Step("jobId").GetCode());
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1235 ASSERT_EQ(1u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1236 ASSERT_TRUE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1237
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1238 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1239 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1240 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1241 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1242
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1243 ASSERT_THROW(job.Step("jobId"), OrthancException);
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1244 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1245
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1246 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1247 Json::Value s;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1248
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1249 DummyInstancesJob job;
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1250 job.AddInstance("hello");
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1251 ASSERT_EQ(1u, job.GetInstancesCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1252 ASSERT_EQ(1u, job.GetCommandsCount());
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1253 job.AddTrailingStep();
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1254 ASSERT_EQ(1u, job.GetInstancesCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1255 ASSERT_EQ(2u, job.GetCommandsCount());
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2853
diff changeset
1256
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1257 job.Start();
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1258 ASSERT_EQ(2u, job.GetCommandsCount());
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1259 ASSERT_EQ(0u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1260 ASSERT_TRUE(job.HasTrailingStep());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1261 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1262
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1263 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1264 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1265 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1266 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1267
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1268 ASSERT_EQ(JobStepCode_Continue, job.Step("jobId").GetCode());
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1269 ASSERT_EQ(1u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1270 ASSERT_FALSE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1271
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1272 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1273 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1274 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1275 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1276
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1277 ASSERT_EQ(JobStepCode_Success, job.Step("jobId").GetCode());
3040
07ab06af90ed preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
1278 ASSERT_EQ(2u, job.GetPosition());
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1279 ASSERT_TRUE(job.IsTrailingStepDone());
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1280
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1281 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1282 DummyUnserializer unserializer;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1283 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1284 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1285
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3641
diff changeset
1286 ASSERT_THROW(job.Step("jobId"), OrthancException);
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1287 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
1288 }
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1289
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1290
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1291 TEST(JobsSerialization, RemoteModalityParameters)
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1292 {
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1293 Json::Value s;
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1294
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1295 {
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1296 RemoteModalityParameters modality;
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1297 ASSERT_FALSE(modality.IsAdvancedFormatNeeded());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1298 modality.Serialize(s, false);
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1299 ASSERT_EQ(Json::arrayValue, s.type());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1300 ASSERT_FALSE(modality.IsDicomTlsEnabled());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1301 ASSERT_FALSE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1302 ASSERT_EQ(0u, modality.GetTimeout());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1303 }
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1304
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1305 {
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1306 RemoteModalityParameters modality(s);
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1307 ASSERT_FALSE(modality.IsAdvancedFormatNeeded());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1308 ASSERT_EQ("ORTHANC", modality.GetApplicationEntityTitle());
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1309 ASSERT_EQ("127.0.0.1", modality.GetHost());
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1310 ASSERT_EQ(104u, modality.GetPortNumber());
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1311 ASSERT_EQ(ModalityManufacturer_Generic, modality.GetManufacturer());
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1312 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Echo));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1313 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Find));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1314 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Get));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1315 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Store));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1316 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Move));
3602
085283445db0 AllowNAction in remote modality parameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3561
diff changeset
1317 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NAction));
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1318 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NEventReport));
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3878
diff changeset
1319 ASSERT_TRUE(modality.IsTranscodingAllowed());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1320 ASSERT_FALSE(modality.IsDicomTlsEnabled());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1321 ASSERT_FALSE(modality.HasLocalAet());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1322 ASSERT_THROW(modality.GetLocalAet(), OrthancException);
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1323 ASSERT_FALSE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1324 ASSERT_EQ(0u, modality.GetTimeout());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1325 }
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1326
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1327 s = Json::nullValue;
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1328
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1329 {
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1330 RemoteModalityParameters modality;
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1331 ASSERT_THROW(modality.SetPortNumber(0), OrthancException);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1332 ASSERT_THROW(modality.SetPortNumber(65535), OrthancException);
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1333 modality.SetApplicationEntityTitle("HELLO");
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1334 modality.SetHost("world");
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1335 modality.SetPortNumber(45);
3561
bdafff1ce443 C-Find SCU at Instance level now sets the 0008,0052 tag to IMAGE per default (was INSTANCE). Source: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/orthanc-users/FYxHXzlaQ0M/rn6d0SowAAAJ
Alain Mazy <alain@mazy.be>
parents: 3240
diff changeset
1336 modality.SetManufacturer(ModalityManufacturer_GenericNoWildcardInDates);
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1337 ASSERT_FALSE(modality.IsAdvancedFormatNeeded());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1338 modality.Serialize(s, true);
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1339 ASSERT_EQ(Json::objectValue, s.type());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1340 ASSERT_FALSE(modality.HasLocalAet());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1341 ASSERT_FALSE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1342 ASSERT_EQ(0u, modality.GetTimeout());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1343 }
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1344
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1345 {
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1346 RemoteModalityParameters modality(s);
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1347 ASSERT_EQ("HELLO", modality.GetApplicationEntityTitle());
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1348 ASSERT_EQ("world", modality.GetHost());
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1349 ASSERT_EQ(45u, modality.GetPortNumber());
3561
bdafff1ce443 C-Find SCU at Instance level now sets the 0008,0052 tag to IMAGE per default (was INSTANCE). Source: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/orthanc-users/FYxHXzlaQ0M/rn6d0SowAAAJ
Alain Mazy <alain@mazy.be>
parents: 3240
diff changeset
1350 ASSERT_EQ(ModalityManufacturer_GenericNoWildcardInDates, modality.GetManufacturer());
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1351 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Echo));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1352 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Find));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1353 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Get));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1354 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Store));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1355 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_Move));
3602
085283445db0 AllowNAction in remote modality parameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3561
diff changeset
1356 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NAction));
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1357 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NEventReport));
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3878
diff changeset
1358 ASSERT_TRUE(modality.IsTranscodingAllowed());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1359 ASSERT_FALSE(modality.IsDicomTlsEnabled());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1360 ASSERT_FALSE(modality.HasLocalAet());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1361 ASSERT_FALSE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1362 ASSERT_EQ(0u, modality.GetTimeout());
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1363 }
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1364
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1365 s["Port"] = "46";
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1366
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1367 {
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1368 RemoteModalityParameters modality(s);
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1369 ASSERT_EQ(46u, modality.GetPortNumber());
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1370 }
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1371
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1372 s["Port"] = -1; ASSERT_THROW(RemoteModalityParameters m(s), OrthancException);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1373 s["Port"] = 65535; ASSERT_THROW(RemoteModalityParameters m(s), OrthancException);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1374 s["Port"] = "nope"; ASSERT_THROW(RemoteModalityParameters m(s), OrthancException);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1375
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1376 std::set<DicomRequestType> operations;
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1377 operations.insert(DicomRequestType_Echo);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1378 operations.insert(DicomRequestType_Find);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1379 operations.insert(DicomRequestType_Get);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1380 operations.insert(DicomRequestType_Move);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1381 operations.insert(DicomRequestType_Store);
3602
085283445db0 AllowNAction in remote modality parameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3561
diff changeset
1382 operations.insert(DicomRequestType_NAction);
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1383 operations.insert(DicomRequestType_NEventReport);
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1384
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1385 ASSERT_EQ(7u, operations.size());
2872
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1386
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1387 for (std::set<DicomRequestType>::const_iterator
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1388 it = operations.begin(); it != operations.end(); ++it)
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1389 {
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1390 {
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1391 RemoteModalityParameters modality;
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1392 modality.SetRequestAllowed(*it, false);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1393 ASSERT_TRUE(modality.IsAdvancedFormatNeeded());
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1394
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1395 modality.Serialize(s, false);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1396 ASSERT_EQ(Json::objectValue, s.type());
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1397 }
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1398
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1399 {
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1400 RemoteModalityParameters modality(s);
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1401
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1402 ASSERT_FALSE(modality.IsRequestAllowed(*it));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1403
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1404 for (std::set<DicomRequestType>::const_iterator
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1405 it2 = operations.begin(); it2 != operations.end(); ++it2)
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1406 {
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1407 if (*it2 != *it)
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1408 {
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1409 ASSERT_TRUE(modality.IsRequestAllowed(*it2));
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1410 }
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1411 }
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1412 }
9d08edde614b Possibility to restrict the allowed DICOM commands for each modality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2871
diff changeset
1413 }
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1414
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1415 s = Json::nullValue;
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1416
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1417 {
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1418 RemoteModalityParameters modality;
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1419 modality.SetLocalAet("hello");
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1420 modality.SetTimeout(42);
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1421 ASSERT_TRUE(modality.IsAdvancedFormatNeeded());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1422 modality.Serialize(s, true);
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1423 ASSERT_EQ(Json::objectValue, s.type());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1424 ASSERT_TRUE(modality.HasLocalAet());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1425 ASSERT_TRUE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1426 ASSERT_EQ(42u, modality.GetTimeout());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1427 }
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1428
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1429 {
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1430 RemoteModalityParameters modality(s);
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1431 ASSERT_TRUE(modality.HasLocalAet());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1432 ASSERT_EQ("hello", modality.GetLocalAet());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1433 ASSERT_TRUE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1434 ASSERT_EQ(42u, modality.GetTimeout());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1435 }
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1436
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1437 {
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1438 Json::Value t;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1439 t["AllowStorageCommitment"] = false;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1440 t["AET"] = "AET";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1441 t["Host"] = "host";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1442 t["Port"] = "104";
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1443
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1444 RemoteModalityParameters modality(t);
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1445 ASSERT_TRUE(modality.IsAdvancedFormatNeeded());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1446 ASSERT_EQ("AET", modality.GetApplicationEntityTitle());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1447 ASSERT_EQ("host", modality.GetHost());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1448 ASSERT_EQ(104u, modality.GetPortNumber());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1449 ASSERT_FALSE(modality.IsRequestAllowed(DicomRequestType_NAction));
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1450 ASSERT_FALSE(modality.IsRequestAllowed(DicomRequestType_NEventReport));
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3878
diff changeset
1451 ASSERT_TRUE(modality.IsTranscodingAllowed());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1452 ASSERT_FALSE(modality.IsDicomTlsEnabled());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1453 ASSERT_FALSE(modality.HasLocalAet());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1454 ASSERT_THROW(modality.GetLocalAet(), OrthancException);
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1455 ASSERT_FALSE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1456 ASSERT_EQ(0u, modality.GetTimeout());
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1457 }
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1458
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1459 {
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1460 Json::Value t;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1461 t["AllowNAction"] = false;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1462 t["AllowNEventReport"] = true;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1463 t["AET"] = "AET";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1464 t["Host"] = "host";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1465 t["Port"] = "104";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1466 t["AllowTranscoding"] = false;
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1467 t["UseDicomTls"] = true;
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1468 t["LocalAet"] = "world";
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1469 t["Timeout"] = 20;
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1470
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1471 RemoteModalityParameters modality(t);
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1472 ASSERT_TRUE(modality.IsAdvancedFormatNeeded());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1473 ASSERT_EQ("AET", modality.GetApplicationEntityTitle());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1474 ASSERT_EQ("host", modality.GetHost());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1475 ASSERT_EQ(104u, modality.GetPortNumber());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1476 ASSERT_FALSE(modality.IsRequestAllowed(DicomRequestType_NAction));
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1477 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NEventReport));
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3878
diff changeset
1478 ASSERT_FALSE(modality.IsTranscodingAllowed());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1479 ASSERT_TRUE(modality.IsDicomTlsEnabled());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1480 ASSERT_TRUE(modality.HasLocalAet());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1481 ASSERT_EQ("world", modality.GetLocalAet());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1482 ASSERT_TRUE(modality.HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1483 ASSERT_EQ(20u, modality.GetTimeout());
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1484 }
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1485
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1486 {
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1487 Json::Value t;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1488 t["AllowNAction"] = true;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1489 t["AllowNEventReport"] = true;
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1490 t["AET"] = "AET";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1491 t["Host"] = "host";
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1492 t["Port"] = "104";
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1493
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
1494 RemoteModalityParameters modality(t);
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1495 ASSERT_FALSE(modality.IsAdvancedFormatNeeded());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1496 ASSERT_EQ("AET", modality.GetApplicationEntityTitle());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1497 ASSERT_EQ("host", modality.GetHost());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1498 ASSERT_EQ(104u, modality.GetPortNumber());
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1499 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NAction));
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1500 ASSERT_TRUE(modality.IsRequestAllowed(DicomRequestType_NEventReport));
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3878
diff changeset
1501 ASSERT_TRUE(modality.IsTranscodingAllowed());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1502 ASSERT_FALSE(modality.IsDicomTlsEnabled());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1503 ASSERT_FALSE(modality.HasLocalAet());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1504 ASSERT_THROW(modality.GetLocalAet(), OrthancException);
3613
c1e2b91c2ab4 all the abstractions for storage commitment are available
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3602
diff changeset
1505 }
2871
6eebc2eb3168 refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2868
diff changeset
1506 }
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1507
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1508
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1509
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1510 TEST(JobsSerialization, DicomAssociationParameters)
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1511 {
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1512 {
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1513 DicomAssociationParameters a;
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1514
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1515 Json::Value v = Json::objectValue;
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1516 a.SerializeJob(v);
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1517 ASSERT_EQ(Json::objectValue, v.type());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1518 ASSERT_EQ("ORTHANC", v["LocalAet"].asString());
4457
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
1519 ASSERT_EQ(DicomAssociationParameters::GetDefaultTimeout(), v["Timeout"].asUInt());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1520 ASSERT_TRUE(v.isMember("Remote"));
4451
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1521 ASSERT_TRUE(v.isMember("MaximumPduLength"));
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1522
4656
82a314325351 New configuration option: "DicomTlsRemoteCertificateRequired"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4518
diff changeset
1523 ASSERT_EQ(5u, v.getMemberNames().size());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1524
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1525 DicomAssociationParameters b;
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1526 b.UnserializeJob(v);
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1527 ASSERT_EQ("ANY-SCP", b.GetRemoteModality().GetApplicationEntityTitle());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1528 ASSERT_EQ("127.0.0.1", b.GetRemoteModality().GetHost());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1529 ASSERT_EQ(104u, b.GetRemoteModality().GetPortNumber());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1530 ASSERT_EQ("ORTHANC", b.GetLocalApplicationEntityTitle());
4451
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1531 ASSERT_EQ(DicomAssociationParameters::GetDefaultMaximumPduLength(), b.GetMaximumPduLength());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1532 ASSERT_FALSE(b.GetRemoteModality().IsDicomTlsEnabled());
4463
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1533 ASSERT_FALSE(b.GetRemoteModality().HasLocalAet());
522e13a60cfc "LocalAet" in "DicomModalities" to overwrite global "DicomAet" for SCU on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4457
diff changeset
1534 ASSERT_THROW(b.GetRemoteModality().GetLocalAet(), OrthancException);
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1535 ASSERT_FALSE(b.GetRemoteModality().HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1536 ASSERT_EQ(0u, b.GetRemoteModality().GetTimeout());
4656
82a314325351 New configuration option: "DicomTlsRemoteCertificateRequired"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4518
diff changeset
1537 ASSERT_TRUE(b.IsRemoteCertificateRequired());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1538 }
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1539
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1540 {
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1541 RemoteModalityParameters p;
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1542 p.SetApplicationEntityTitle("WORLD");
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1543 p.SetPortNumber(4242);
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1544 p.SetHost("hello.world.com");
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1545 p.SetDicomTlsEnabled(true);
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1546 p.SetTimeout(42);
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1547
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1548 DicomAssociationParameters a("HELLO", p);
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1549 a.SetOwnCertificatePath("key", "crt");
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1550 a.SetTrustedCertificatesPath("trusted");
4656
82a314325351 New configuration option: "DicomTlsRemoteCertificateRequired"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4518
diff changeset
1551 a.SetRemoteCertificateRequired(false);
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1552
4451
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1553 ASSERT_THROW(a.SetMaximumPduLength(4095), OrthancException);
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1554 ASSERT_THROW(a.SetMaximumPduLength(131073), OrthancException);
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1555 a.SetMaximumPduLength(4096);
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1556 a.SetMaximumPduLength(131072);
f4dbdb2dcba6 new configuration option "MaximumPduLength" to tune the maximum PDU length
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4438
diff changeset
1557
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1558 Json::Value v = Json::objectValue;
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1559 a.SerializeJob(v);
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1560
4656
82a314325351 New configuration option: "DicomTlsRemoteCertificateRequired"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4518
diff changeset
1561 ASSERT_EQ(8u, v.getMemberNames().size());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1562
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1563 DicomAssociationParameters b = DicomAssociationParameters::UnserializeJob(v);
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1564
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1565 ASSERT_EQ("WORLD", b.GetRemoteModality().GetApplicationEntityTitle());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1566 ASSERT_EQ("hello.world.com", b.GetRemoteModality().GetHost());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1567 ASSERT_EQ(4242u, b.GetRemoteModality().GetPortNumber());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1568 ASSERT_EQ("HELLO", b.GetLocalApplicationEntityTitle());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1569 ASSERT_TRUE(b.GetRemoteModality().IsDicomTlsEnabled());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1570 ASSERT_EQ("key", b.GetOwnPrivateKeyPath());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1571 ASSERT_EQ("crt", b.GetOwnCertificatePath());
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1572 ASSERT_EQ("trusted", b.GetTrustedCertificatesPath());
4457
789676a8c96a Refactoring and improvements to the cache of DICOM files in ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4451
diff changeset
1573 ASSERT_EQ(131072u, b.GetMaximumPduLength());
4518
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1574 ASSERT_TRUE(b.GetRemoteModality().HasTimeout());
cb8fcecf1b02 new option "Timeout" in "DicomModalities" to set DICOM SCU timeout on a per-modality basis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4463
diff changeset
1575 ASSERT_EQ(42u, b.GetRemoteModality().GetTimeout());
4656
82a314325351 New configuration option: "DicomTlsRemoteCertificateRequired"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4518
diff changeset
1576 ASSERT_FALSE(b.IsRemoteCertificateRequired());
4438
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1577 }
4a4e33c9082d configuration options for DICOM TLS in Orthanc SCU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1578 }
4775
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1579
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1580
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1581 TEST(SerializationToolbox, Numbers)
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1582 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1583 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1584 int32_t i;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1585 ASSERT_FALSE(SerializationToolbox::ParseInteger32(i, ""));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1586 ASSERT_FALSE(SerializationToolbox::ParseInteger32(i, "ee"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1587 ASSERT_TRUE(SerializationToolbox::ParseInteger32(i, "42")); ASSERT_EQ(42, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1588 ASSERT_TRUE(SerializationToolbox::ParseInteger32(i, "-42")); ASSERT_EQ(-42, i);
4779
4f368230f32b fix for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4775
diff changeset
1589 ASSERT_TRUE(SerializationToolbox::ParseInteger32(i, "-2147483648")); ASSERT_EQ(-2147483648l, i);
4f368230f32b fix for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4775
diff changeset
1590 ASSERT_TRUE(SerializationToolbox::ParseInteger32(i, "2147483647")); ASSERT_EQ(2147483647l, i);
4775
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1591 ASSERT_FALSE(SerializationToolbox::ParseInteger32(i, "-2147483649"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1592 ASSERT_FALSE(SerializationToolbox::ParseInteger32(i, "2147483648"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1593 ASSERT_FALSE(SerializationToolbox::ParseInteger32(i, "-2\\-3\\-4"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1594 ASSERT_TRUE(SerializationToolbox::ParseFirstInteger32(i, "-2\\-3\\-4")); ASSERT_EQ(-2, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1595 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1596
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1597 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1598 uint32_t i;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1599 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger32(i, ""));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1600 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger32(i, "ee"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1601 ASSERT_TRUE(SerializationToolbox::ParseUnsignedInteger32(i, "42")); ASSERT_EQ(42u, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1602 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger32(i, "-42"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1603 ASSERT_TRUE(SerializationToolbox::ParseUnsignedInteger32(i, "4294967295")); ASSERT_EQ(4294967295u, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1604 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger32(i, "4294967296"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1605 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger32(i, "2\\3\\4"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1606 ASSERT_TRUE(SerializationToolbox::ParseFirstUnsignedInteger32(i, "2\\3\\4")); ASSERT_EQ(2u, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1607 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1608
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1609 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1610 int64_t i;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1611 ASSERT_FALSE(SerializationToolbox::ParseInteger64(i, ""));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1612 ASSERT_FALSE(SerializationToolbox::ParseInteger64(i, "ee"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1613 ASSERT_TRUE(SerializationToolbox::ParseInteger64(i, "42")); ASSERT_EQ(42, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1614 ASSERT_TRUE(SerializationToolbox::ParseInteger64(i, "-42")); ASSERT_EQ(-42, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1615 ASSERT_TRUE(SerializationToolbox::ParseInteger64(i, "-2147483649")); ASSERT_EQ(-2147483649ll, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1616 ASSERT_TRUE(SerializationToolbox::ParseInteger64(i, "2147483648")); ASSERT_EQ(2147483648ll, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1617 ASSERT_FALSE(SerializationToolbox::ParseInteger64(i, "-2\\-3\\-4"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1618 ASSERT_TRUE(SerializationToolbox::ParseFirstInteger64(i, "-2\\-3\\-4")); ASSERT_EQ(-2, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1619 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1620
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1621 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1622 uint64_t i;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1623 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger64(i, ""));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1624 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger64(i, "ee"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1625 ASSERT_TRUE(SerializationToolbox::ParseUnsignedInteger64(i, "42")); ASSERT_EQ(42u, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1626 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger64(i, "-42"));
4779
4f368230f32b fix for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4775
diff changeset
1627 ASSERT_TRUE(SerializationToolbox::ParseUnsignedInteger64(i, "4294967296")); ASSERT_EQ(4294967296lu, i);
4775
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1628 ASSERT_FALSE(SerializationToolbox::ParseUnsignedInteger64(i, "2\\3\\4"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1629 ASSERT_TRUE(SerializationToolbox::ParseFirstUnsignedInteger64(i, "2\\3\\4")); ASSERT_EQ(2u, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1630 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1631
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1632 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1633 float i;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1634 ASSERT_FALSE(SerializationToolbox::ParseFloat(i, ""));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1635 ASSERT_FALSE(SerializationToolbox::ParseFloat(i, "ee"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1636 ASSERT_TRUE(SerializationToolbox::ParseFloat(i, "42")); ASSERT_FLOAT_EQ(42.0f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1637 ASSERT_TRUE(SerializationToolbox::ParseFloat(i, "-42")); ASSERT_FLOAT_EQ(-42.0f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1638 ASSERT_FALSE(SerializationToolbox::ParseFloat(i, "2\\3\\4"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1639 ASSERT_TRUE(SerializationToolbox::ParseFirstFloat(i, "1.367\\2.367\\3.367")); ASSERT_FLOAT_EQ(1.367f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1640
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1641 ASSERT_TRUE(SerializationToolbox::ParseFloat(i, "1.2")); ASSERT_FLOAT_EQ(1.2f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1642 ASSERT_TRUE(SerializationToolbox::ParseFloat(i, "-1.2e+2")); ASSERT_FLOAT_EQ(-120.0f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1643 ASSERT_TRUE(SerializationToolbox::ParseFloat(i, "-1e-2")); ASSERT_FLOAT_EQ(-0.01f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1644 ASSERT_TRUE(SerializationToolbox::ParseFloat(i, "1.3671875")); ASSERT_FLOAT_EQ(1.3671875f, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1645 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1646
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1647 {
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1648 double i;
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1649 ASSERT_FALSE(SerializationToolbox::ParseDouble(i, ""));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1650 ASSERT_FALSE(SerializationToolbox::ParseDouble(i, "ee"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1651 ASSERT_TRUE(SerializationToolbox::ParseDouble(i, "42")); ASSERT_DOUBLE_EQ(42.0, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1652 ASSERT_TRUE(SerializationToolbox::ParseDouble(i, "-42")); ASSERT_DOUBLE_EQ(-42.0, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1653 ASSERT_FALSE(SerializationToolbox::ParseDouble(i, "2\\3\\4"));
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1654 ASSERT_TRUE(SerializationToolbox::ParseFirstDouble(i, "1.367\\2.367\\3.367")); ASSERT_DOUBLE_EQ(1.367, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1655
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1656 ASSERT_TRUE(SerializationToolbox::ParseDouble(i, "1.2")); ASSERT_DOUBLE_EQ(1.2, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1657 ASSERT_TRUE(SerializationToolbox::ParseDouble(i, "-1.2e+2")); ASSERT_DOUBLE_EQ(-120.0, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1658 ASSERT_TRUE(SerializationToolbox::ParseDouble(i, "-1e-2")); ASSERT_DOUBLE_EQ(-0.01, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1659 ASSERT_TRUE(SerializationToolbox::ParseDouble(i, "1.3671875")); ASSERT_DOUBLE_EQ(1.3671875, i);
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1660 }
add0337b928a refactoring parsing of numbers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4687
diff changeset
1661 }