annotate Framework/Plugins/IndexUnitTests.h @ 395:a7a029043670 db-protobuf

integration mainline->db-protobuf
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Apr 2023 14:53:57 +0200
parents 3d6886f3e5b3
children 91124cc8a8c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
389
3d6886f3e5b3 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
3d6886f3e5b3 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
28
c0cb5d2cd696 checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 27
diff changeset
25 #include "../Common/ImplicitTransaction.h"
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
26 #include "DatabaseBackendAdapterV2.h"
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
27 #include "GlobalProperties.h"
28
c0cb5d2cd696 checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 27
diff changeset
28
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
29 #include <Compatibility.h> // For std::unique_ptr<>
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
30
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <orthanc/OrthancCDatabasePlugin.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <gtest/gtest.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <list>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
273
07881ac5404b fix build against system-wide orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
36 #if !defined(ORTHANC_DATABASE_VERSION)
07881ac5404b fix build against system-wide orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
37 // This happens if using the Orthanc framework system-wide library
07881ac5404b fix build against system-wide orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
38 # define ORTHANC_DATABASE_VERSION 6
07881ac5404b fix build against system-wide orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
39 #endif
07881ac5404b fix build against system-wide orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 266
diff changeset
40
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
42 #if ORTHANC_ENABLE_POSTGRESQL == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
43 # define HAS_REVISIONS 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
44 #elif ORTHANC_ENABLE_MYSQL == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
45 # define HAS_REVISIONS 0
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
46 #elif ORTHANC_ENABLE_SQLITE == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
47 # define HAS_REVISIONS 1
309
d192bfd0e752 tagging globalParameters_ as static in MySQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
48 #elif ORTHANC_ENABLE_ODBC == 1
d192bfd0e752 tagging globalParameters_ as static in MySQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
49 # define HAS_REVISIONS 1
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
50 #else
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
51 # error Unknown database backend
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
52 #endif
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
53
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
54
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
55 namespace Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
56 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
57 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
58 * Mock enumeration inspired from the source code of Orthanc... only
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
59 * for use in the unit tests!
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
60 * https://hg.orthanc-server.com/orthanc/file/default/OrthancServer/Sources/ServerEnumerations.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
61 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
62 enum MetadataType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
63 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
64 MetadataType_ModifiedFrom,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
65 MetadataType_LastUpdate
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
66 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
67 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
68
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
69
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
70 /**
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
71 * This is a sample UTF8 string that is the concatenation of a Korean
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
72 * and a Kanji text. Check out "utf8raw" in
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
73 * "OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp" for the
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
74 * sources of these binary values.
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
75 **/
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
76 static const uint8_t UTF8[] = {
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
77 // cf. TEST(Toolbox, EncodingsKorean)
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
78 0x48, 0x6f, 0x6e, 0x67, 0x5e, 0x47, 0x69, 0x6c, 0x64, 0x6f, 0x6e, 0x67, 0x3d, 0xe6,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
79 0xb4, 0xaa, 0x5e, 0xe5, 0x90, 0x89, 0xe6, 0xb4, 0x9e, 0x3d, 0xed, 0x99, 0x8d, 0x5e,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
80 0xea, 0xb8, 0xb8, 0xeb, 0x8f, 0x99,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
81
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
82 // cf. TEST(Toolbox, EncodingsJapaneseKanji)
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
83 0x59, 0x61, 0x6d, 0x61, 0x64, 0x61, 0x5e, 0x54, 0x61, 0x72, 0x6f, 0x75, 0x3d, 0xe5,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
84 0xb1, 0xb1, 0xe7, 0x94, 0xb0, 0x5e, 0xe5, 0xa4, 0xaa, 0xe9, 0x83, 0x8e, 0x3d, 0xe3,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
85 0x82, 0x84, 0xe3, 0x81, 0xbe, 0xe3, 0x81, 0xa0, 0x5e, 0xe3, 0x81, 0x9f, 0xe3, 0x82,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
86 0x8d, 0xe3, 0x81, 0x86,
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
87
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
88 // End of text
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
89 0x00
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
90 };
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
91
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
92
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
93 static std::unique_ptr<OrthancPluginAttachment> expectedAttachment;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 static std::list<OrthancPluginDicomTag> expectedDicomTags;
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
95 static std::unique_ptr<OrthancPluginExportedResource> expectedExported;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
97 static std::map<std::string, OrthancPluginResourceType> deletedResources;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
98 static std::unique_ptr< std::pair<std::string, OrthancPluginResourceType> > remainingAncestor;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
99 static std::set<std::string> deletedAttachments;
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
100 static unsigned int countDicomTags = 0;
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
101
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
102
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 static void CheckAttachment(const OrthancPluginAttachment& attachment)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 ASSERT_STREQ(expectedAttachment->uuid, attachment.uuid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ASSERT_EQ(expectedAttachment->contentType, attachment.contentType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ASSERT_EQ(expectedAttachment->uncompressedSize, attachment.uncompressedSize);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 ASSERT_STREQ(expectedAttachment->uncompressedHash, attachment.uncompressedHash);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ASSERT_EQ(expectedAttachment->compressionType, attachment.compressionType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ASSERT_EQ(expectedAttachment->compressedSize, attachment.compressedSize);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ASSERT_STREQ(expectedAttachment->compressedHash, attachment.compressedHash);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 static void CheckExportedResource(const OrthancPluginExportedResource& exported)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
311
5f0d5f849944 fix unit tests if resuning the same database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 309
diff changeset
116 // ASSERT_EQ(expectedExported->seq, exported.seq);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 ASSERT_EQ(expectedExported->resourceType, exported.resourceType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 ASSERT_STREQ(expectedExported->publicId, exported.publicId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ASSERT_STREQ(expectedExported->modality, exported.modality);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ASSERT_STREQ(expectedExported->date, exported.date);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ASSERT_STREQ(expectedExported->patientId, exported.patientId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ASSERT_STREQ(expectedExported->studyInstanceUid, exported.studyInstanceUid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 ASSERT_STREQ(expectedExported->seriesInstanceUid, exported.seriesInstanceUid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_STREQ(expectedExported->sopInstanceUid, exported.sopInstanceUid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 static void CheckDicomTag(const OrthancPluginDicomTag& tag)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 for (std::list<OrthancPluginDicomTag>::const_iterator
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 it = expectedDicomTags.begin(); it != expectedDicomTags.end(); ++it)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 if (it->group == tag.group &&
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 it->element == tag.element &&
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 !strcmp(it->value, tag.value))
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 // OK, match
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 return;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 ASSERT_TRUE(0); // Error
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 static OrthancPluginErrorCode InvokeService(struct _OrthancPluginContext_t* context,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 _OrthancPluginService service,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 const void* params)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
150 switch (service)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
152 case _OrthancPluginService_DatabaseAnswer:
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
154 const _OrthancPluginDatabaseAnswer& answer =
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
155 *reinterpret_cast<const _OrthancPluginDatabaseAnswer*>(params);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
156
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
157 switch (answer.type)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
159 case _OrthancPluginDatabaseAnswerType_Attachment:
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
160 {
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
161 const OrthancPluginAttachment& attachment =
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
162 *reinterpret_cast<const OrthancPluginAttachment*>(answer.valueGeneric);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
163 CheckAttachment(attachment);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
164 break;
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
165 }
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
166
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
167 case _OrthancPluginDatabaseAnswerType_ExportedResource:
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
168 {
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
169 const OrthancPluginExportedResource& attachment =
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
170 *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
171 CheckExportedResource(attachment);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
172 break;
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
173 }
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
174
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
175 case _OrthancPluginDatabaseAnswerType_DicomTag:
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
176 {
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
177 const OrthancPluginDicomTag& tag =
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
178 *reinterpret_cast<const OrthancPluginDicomTag*>(answer.valueGeneric);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
179 CheckDicomTag(tag);
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
180 countDicomTags++;
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
181 break;
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
182 }
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
183
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
184 case _OrthancPluginDatabaseAnswerType_DeletedResource:
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
185 deletedResources[answer.valueString] = static_cast<OrthancPluginResourceType>(answer.valueInt32);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
186 break;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
187
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
188 case _OrthancPluginDatabaseAnswerType_RemainingAncestor:
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
189 remainingAncestor.reset(new std::pair<std::string, OrthancPluginResourceType>());
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
190 *remainingAncestor = std::make_pair(answer.valueString, static_cast<OrthancPluginResourceType>(answer.valueInt32));
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
191 break;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
192
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
193 case _OrthancPluginDatabaseAnswerType_DeletedAttachment:
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
194 deletedAttachments.insert(reinterpret_cast<const OrthancPluginAttachment*>(answer.valueGeneric)->uuid);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
195 break;
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
196
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
197 default:
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
198 printf("Unhandled message: %d\n", answer.type);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
199 break;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
202 return OrthancPluginErrorCode_Success;
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
203 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
205 case _OrthancPluginService_GetExpectedDatabaseVersion:
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
206 {
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
207 const _OrthancPluginReturnSingleValue& p =
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
208 *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(params);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
209 *(p.resultUint32) = ORTHANC_DATABASE_VERSION;
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
210 return OrthancPluginErrorCode_Success;
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
211 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
199
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
213 default:
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
214 assert(0);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
215 printf("Service not emulated: %d\n", service);
8cae98f73d53 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
216 return OrthancPluginErrorCode_NotImplemented;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 TEST(IndexBackend, Basic)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 using namespace OrthancDatabases;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 OrthancPluginContext context;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 context.pluginsManager = NULL;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 context.orthancVersion = "mainline";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 context.Free = ::free;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 context.InvokeService = InvokeService;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
28
c0cb5d2cd696 checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 27
diff changeset
231 ImplicitTransaction::SetErrorOnDoubleExecution(true);
c0cb5d2cd696 checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 27
diff changeset
232
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 #if ORTHANC_ENABLE_POSTGRESQL == 1
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
234 PostgreSQLIndex db(&context, globalParameters_);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 db.SetClearAll(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 #elif ORTHANC_ENABLE_MYSQL == 1
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
237 MySQLIndex db(&context, globalParameters_);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 db.SetClearAll(true);
309
d192bfd0e752 tagging globalParameters_ as static in MySQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
239 #elif ORTHANC_ENABLE_ODBC == 1
d192bfd0e752 tagging globalParameters_ as static in MySQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 307
diff changeset
240 OdbcIndex db(&context, connectionString_);
319
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
241 #elif ORTHANC_ENABLE_SQLITE == 1 // Must be the last one
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
242 SQLiteIndex db(&context); // Open in memory
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 #else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 # error Unsupported database backend
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 #endif
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
204
7299410c3d61 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
247 db.SetOutputFactory(new DatabaseBackendAdapterV2::Factory(&context, NULL));
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
248
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
249 std::unique_ptr<DatabaseManager> manager(IndexBackend::CreateSingleDatabaseManager(db));
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
250
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
251 std::unique_ptr<IDatabaseBackendOutput> output(db.CreateOutput());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 std::string s;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
254 ASSERT_TRUE(db.LookupGlobalProperty(s, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 ASSERT_EQ("6", s);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
257 db.SetGlobalProperty(*manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal9, "Hello");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
258 ASSERT_TRUE(db.LookupGlobalProperty(s, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal9));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 ASSERT_EQ("Hello", s);
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
260 db.SetGlobalProperty(*manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal9, "HelloWorld");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
261 ASSERT_TRUE(db.LookupGlobalProperty(s, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal9));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 ASSERT_EQ("HelloWorld", s);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
301
2447c290fc73 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
264 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
2447c290fc73 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
265 ASSERT_EQ(0u, db.GetResourcesCount(*manager, OrthancPluginResourceType_Patient));
2447c290fc73 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
266 ASSERT_EQ(0u, db.GetResourcesCount(*manager, OrthancPluginResourceType_Study));
2447c290fc73 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
267 ASSERT_EQ(0u, db.GetResourcesCount(*manager, OrthancPluginResourceType_Series));
2447c290fc73 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 289
diff changeset
268
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
269 int64_t a = db.CreateResource(*manager, "study", OrthancPluginResourceType_Study);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
270 ASSERT_TRUE(db.IsExistingResource(*manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
271 ASSERT_FALSE(db.IsExistingResource(*manager, a + 1));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 int64_t b;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 OrthancPluginResourceType t;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
275 ASSERT_FALSE(db.LookupResource(b, t, *manager, "world"));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
276 ASSERT_TRUE(db.LookupResource(b, t, *manager, "study"));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 ASSERT_EQ(a, b);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 ASSERT_EQ(OrthancPluginResourceType_Study, t);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
280 b = db.CreateResource(*manager, "series", OrthancPluginResourceType_Series);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 ASSERT_NE(a, b);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
283 ASSERT_EQ("study", db.GetPublicId(*manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
284 ASSERT_EQ("series", db.GetPublicId(*manager, b));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
285 ASSERT_EQ(OrthancPluginResourceType_Study, db.GetResourceType(*manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
286 ASSERT_EQ(OrthancPluginResourceType_Series, db.GetResourceType(*manager, b));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
288 db.AttachChild(*manager, a, b);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 int64_t c;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
291 ASSERT_FALSE(db.LookupParent(c, *manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
292 ASSERT_TRUE(db.LookupParent(c, *manager, b));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 ASSERT_EQ(a, c);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
295 c = db.CreateResource(*manager, "series2", OrthancPluginResourceType_Series);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
296 db.AttachChild(*manager, a, c);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
298 ASSERT_EQ(3u, db.GetAllResourcesCount(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
299 ASSERT_EQ(0u, db.GetResourcesCount(*manager, OrthancPluginResourceType_Patient));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
300 ASSERT_EQ(1u, db.GetResourcesCount(*manager, OrthancPluginResourceType_Study));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
301 ASSERT_EQ(2u, db.GetResourcesCount(*manager, OrthancPluginResourceType_Series));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
303 ASSERT_FALSE(db.GetParentPublicId(s, *manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
304 ASSERT_TRUE(db.GetParentPublicId(s, *manager, b)); ASSERT_EQ("study", s);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
305 ASSERT_TRUE(db.GetParentPublicId(s, *manager, c)); ASSERT_EQ("study", s);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 std::list<std::string> children;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
308 db.GetChildren(children, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ASSERT_EQ(2u, children.size());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
310 db.GetChildren(children, *manager, b);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 ASSERT_EQ(0u, children.size());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
312 db.GetChildren(children, *manager, c);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 ASSERT_EQ(0u, children.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 std::list<std::string> cp;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
316 db.GetChildrenPublicId(cp, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 ASSERT_EQ(2u, cp.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 ASSERT_TRUE(cp.front() == "series" || cp.front() == "series2");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 ASSERT_TRUE(cp.back() == "series" || cp.back() == "series2");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 ASSERT_NE(cp.front(), cp.back());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 std::list<std::string> pub;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
323 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Patient);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 ASSERT_EQ(0u, pub.size());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
325 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Study);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 ASSERT_EQ(1u, pub.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 ASSERT_EQ("study", pub.front());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
328 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Series);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 ASSERT_EQ(2u, pub.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 ASSERT_TRUE(pub.front() == "series" || pub.front() == "series2");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 ASSERT_TRUE(pub.back() == "series" || pub.back() == "series2");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 ASSERT_NE(pub.front(), pub.back());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 std::list<int64_t> ci;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
335 db.GetChildrenInternalId(ci, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 ASSERT_EQ(2u, ci.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 ASSERT_TRUE(ci.front() == b || ci.front() == c);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 ASSERT_TRUE(ci.back() == b || ci.back() == c);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 ASSERT_NE(ci.front(), ci.back());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
341 db.SetMetadata(*manager, a, Orthanc::MetadataType_ModifiedFrom, "modified", 42);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
342 db.SetMetadata(*manager, a, Orthanc::MetadataType_LastUpdate, "update2", 43);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
343 int64_t revision = -1;
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
344 ASSERT_FALSE(db.LookupMetadata(s, revision, *manager, b, Orthanc::MetadataType_LastUpdate));
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
345 ASSERT_TRUE(db.LookupMetadata(s, revision, *manager, a, Orthanc::MetadataType_LastUpdate));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 ASSERT_EQ("update2", s);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
347
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
348 #if HAS_REVISIONS == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
349 ASSERT_EQ(43, revision);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
350 #else
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
351 ASSERT_EQ(0, revision);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
352 #endif
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
353
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
354 db.SetMetadata(*manager, a, Orthanc::MetadataType_LastUpdate, reinterpret_cast<const char*>(UTF8), 44);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
355 ASSERT_TRUE(db.LookupMetadata(s, revision, *manager, a, Orthanc::MetadataType_LastUpdate));
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
356 ASSERT_STREQ(reinterpret_cast<const char*>(UTF8), s.c_str());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
358 #if HAS_REVISIONS == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
359 ASSERT_EQ(44, revision);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
360 #else
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
361 ASSERT_EQ(0, revision);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
362 #endif
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
363
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 std::list<int32_t> md;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
365 db.ListAvailableMetadata(md, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 ASSERT_EQ(2u, md.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 ASSERT_TRUE(md.front() == Orthanc::MetadataType_ModifiedFrom || md.back() == Orthanc::MetadataType_ModifiedFrom);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 ASSERT_TRUE(md.front() == Orthanc::MetadataType_LastUpdate || md.back() == Orthanc::MetadataType_LastUpdate);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 std::string mdd;
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
370 ASSERT_TRUE(db.LookupMetadata(mdd, revision, *manager, a, Orthanc::MetadataType_ModifiedFrom));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 ASSERT_EQ("modified", mdd);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
372
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
373 #if HAS_REVISIONS == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
374 ASSERT_EQ(42, revision);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
375 #else
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
376 ASSERT_EQ(0, revision);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
377 #endif
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
378
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
379 ASSERT_TRUE(db.LookupMetadata(mdd, revision, *manager, a, Orthanc::MetadataType_LastUpdate));
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
380 ASSERT_EQ(reinterpret_cast<const char*>(UTF8), mdd);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
382 #if HAS_REVISIONS == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
383 ASSERT_EQ(44, revision);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
384 #else
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
385 ASSERT_EQ(0, revision);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
386 #endif
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
387
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
388 db.ListAvailableMetadata(md, *manager, b);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 ASSERT_EQ(0u, md.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
391 ASSERT_TRUE(db.LookupMetadata(s, revision, *manager, a, Orthanc::MetadataType_LastUpdate));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
392 db.DeleteMetadata(*manager, a, Orthanc::MetadataType_LastUpdate);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
393 ASSERT_FALSE(db.LookupMetadata(s, revision, *manager, a, Orthanc::MetadataType_LastUpdate));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
394 db.DeleteMetadata(*manager, b, Orthanc::MetadataType_LastUpdate);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
395 ASSERT_FALSE(db.LookupMetadata(s, revision, *manager, a, Orthanc::MetadataType_LastUpdate));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
397 db.ListAvailableMetadata(md, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 ASSERT_EQ(1u, md.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 ASSERT_EQ(Orthanc::MetadataType_ModifiedFrom, md.front());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
401 ASSERT_EQ(0u, db.GetTotalCompressedSize(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
402 ASSERT_EQ(0u, db.GetTotalUncompressedSize(*manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 std::list<int32_t> fc;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 OrthancPluginAttachment a1;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 a1.uuid = "uuid1";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 a1.contentType = Orthanc::FileContentType_Dicom;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 a1.uncompressedSize = 42;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 a1.uncompressedHash = "md5_1";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 a1.compressionType = Orthanc::CompressionType_None;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 a1.compressedSize = 42;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 a1.compressedHash = "md5_1";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 OrthancPluginAttachment a2;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 a2.uuid = "uuid2";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 a2.contentType = Orthanc::FileContentType_DicomAsJson;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 a2.uncompressedSize = 4242;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 a2.uncompressedHash = "md5_2";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 a2.compressionType = Orthanc::CompressionType_None;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 a2.compressedSize = 4242;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 a2.compressedHash = "md5_2";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
261
34e2b93a7ac1 implementing interface for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 256
diff changeset
425 db.AddAttachment(*manager, a, a1, 42);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
426 db.ListAvailableAttachments(fc, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 ASSERT_EQ(1u, fc.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 ASSERT_EQ(Orthanc::FileContentType_Dicom, fc.front());
261
34e2b93a7ac1 implementing interface for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 256
diff changeset
429 db.AddAttachment(*manager, a, a2, 43);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
430 db.ListAvailableAttachments(fc, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 ASSERT_EQ(2u, fc.size());
261
34e2b93a7ac1 implementing interface for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 256
diff changeset
432 ASSERT_FALSE(db.LookupAttachment(*output, revision, *manager, b, Orthanc::FileContentType_Dicom));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
434 ASSERT_EQ(4284u, db.GetTotalCompressedSize(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
435 ASSERT_EQ(4284u, db.GetTotalUncompressedSize(*manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 expectedAttachment.reset(new OrthancPluginAttachment);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 expectedAttachment->uuid = "uuid1";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 expectedAttachment->contentType = Orthanc::FileContentType_Dicom;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 expectedAttachment->uncompressedSize = 42;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 expectedAttachment->uncompressedHash = "md5_1";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 expectedAttachment->compressionType = Orthanc::CompressionType_None;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 expectedAttachment->compressedSize = 42;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 expectedAttachment->compressedHash = "md5_1";
261
34e2b93a7ac1 implementing interface for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 256
diff changeset
445 ASSERT_TRUE(db.LookupAttachment(*output, revision, *manager, a, Orthanc::FileContentType_Dicom));
262
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
446
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
447 #if HAS_REVISIONS == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
448 ASSERT_EQ(42, revision);
262
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
449 #else
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
450 ASSERT_EQ(0, revision);
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
451 #endif
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 expectedAttachment.reset(new OrthancPluginAttachment);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 expectedAttachment->uuid = "uuid2";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 expectedAttachment->contentType = Orthanc::FileContentType_DicomAsJson;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 expectedAttachment->uncompressedSize = 4242;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 expectedAttachment->uncompressedHash = "md5_2";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 expectedAttachment->compressionType = Orthanc::CompressionType_None;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 expectedAttachment->compressedSize = 4242;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 expectedAttachment->compressedHash = "md5_2";
261
34e2b93a7ac1 implementing interface for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 256
diff changeset
461 revision = -1;
34e2b93a7ac1 implementing interface for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 256
diff changeset
462 ASSERT_TRUE(db.LookupAttachment(*output, revision, *manager, a, Orthanc::FileContentType_DicomAsJson));
262
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
463
266
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
464 #if HAS_REVISIONS == 1
cc7af42d4f23 Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
465 ASSERT_EQ(43, revision);
262
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
466 #else
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
467 ASSERT_EQ(0, revision);
b0c65094b299 adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 261
diff changeset
468 #endif
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
470 db.ListAvailableAttachments(fc, *manager, b);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 ASSERT_EQ(0u, fc.size());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
472 db.DeleteAttachment(*output, *manager, a, Orthanc::FileContentType_Dicom);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
473 db.ListAvailableAttachments(fc, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 ASSERT_EQ(1u, fc.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 ASSERT_EQ(Orthanc::FileContentType_DicomAsJson, fc.front());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
476 db.DeleteAttachment(*output, *manager, a, Orthanc::FileContentType_DicomAsJson);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
477 db.ListAvailableAttachments(fc, *manager, a);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 ASSERT_EQ(0u, fc.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
480 db.SetIdentifierTag(*manager, a, 0x0010, 0x0020, "patient");
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
481 db.SetIdentifierTag(*manager, a, 0x0020, 0x000d, "study");
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
482 db.SetMainDicomTag(*manager, a, 0x0010, 0x0020, "patient");
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
483 db.SetMainDicomTag(*manager, a, 0x0020, 0x000d, "study");
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
484 db.SetMainDicomTag(*manager, a, 0x0008, 0x1030, reinterpret_cast<const char*>(UTF8));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 expectedDicomTags.clear();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 expectedDicomTags.push_back(OrthancPluginDicomTag());
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
488 expectedDicomTags.back().group = 0x0010;
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
489 expectedDicomTags.back().element = 0x0020;
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
490 expectedDicomTags.back().value = "patient";
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 expectedDicomTags.push_back(OrthancPluginDicomTag());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 expectedDicomTags.back().group = 0x0020;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 expectedDicomTags.back().element = 0x000d;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 expectedDicomTags.back().value = "study";
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
495 expectedDicomTags.push_back(OrthancPluginDicomTag());
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
496 expectedDicomTags.back().group = 0x0008;
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
497 expectedDicomTags.back().element = 0x1030;
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
498 expectedDicomTags.back().value = reinterpret_cast<const char*>(UTF8);
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
499
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
500 countDicomTags = 0;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
501 db.GetMainDicomTags(*output, *manager, a);
335
7ec461718edb unit test of metadata and tags in UTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 321
diff changeset
502 ASSERT_EQ(3u, countDicomTags);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
504 db.LookupIdentifier(ci, *manager, OrthancPluginResourceType_Study, 0x0010, 0x0020,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 OrthancPluginIdentifierConstraint_Equal, "patient");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 ASSERT_EQ(1u, ci.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 ASSERT_EQ(a, ci.front());
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
508 db.LookupIdentifier(ci, *manager, OrthancPluginResourceType_Study, 0x0010, 0x0020,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 OrthancPluginIdentifierConstraint_Equal, "study");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 ASSERT_EQ(0u, ci.size());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
378
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
513 db.LogExportedResource(*manager, OrthancPluginResourceType_Study, "id", "remote", "date",
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
514 "patient", "study", "series", "instance");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 expectedExported.reset(new OrthancPluginExportedResource());
378
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
517 expectedExported->seq = -1;
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
518 expectedExported->resourceType = OrthancPluginResourceType_Study;
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
519 expectedExported->publicId = "id";
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
520 expectedExported->modality = "remote";
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
521 expectedExported->date = "date";
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
522 expectedExported->patientId = "patient";
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
523 expectedExported->studyInstanceUid = "study";
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
524 expectedExported->seriesInstanceUid = "series";
9db9e0275ec0 refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
525 expectedExported->sopInstanceUid = "instance";
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 bool done;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
528 db.GetExportedResources(*output, done, *manager, 0, 10);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
531 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Patient); ASSERT_EQ(0u, pub.size());
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
532 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Study); ASSERT_EQ(1u, pub.size());
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
533 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Series); ASSERT_EQ(2u, pub.size());
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
534 db.GetAllPublicIds(pub, *manager, OrthancPluginResourceType_Instance); ASSERT_EQ(0u, pub.size());
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
535 ASSERT_EQ(3u, db.GetAllResourcesCount(*manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
537 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount(*manager)); // No patient was inserted
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
538 ASSERT_TRUE(db.IsExistingResource(*manager, c));
27
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
539
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
540 {
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
541 // A transaction is needed here for MySQL, as it was not possible
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
542 // to implement recursive deletion of resources using pure SQL
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
543 // statements
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
544 manager->StartTransaction(TransactionType_ReadWrite);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
545
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
546 deletedAttachments.clear();
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
547 deletedResources.clear();
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
548 remainingAncestor.reset();
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
549
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
550 db.DeleteResource(*output, *manager, c);
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
551
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
552 ASSERT_EQ(0u, deletedAttachments.size());
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
553 ASSERT_EQ(1u, deletedResources.size());
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
554 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series2"]);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
555 ASSERT_TRUE(remainingAncestor.get() != NULL);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
556 ASSERT_EQ("study", remainingAncestor->first);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
557 ASSERT_EQ(OrthancPluginResourceType_Study, remainingAncestor->second);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
558
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
559 manager->CommitTransaction();
27
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
560 }
173176f8cef2 jobs branch has disappeared in orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 26
diff changeset
561
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
562 deletedAttachments.clear();
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
563 deletedResources.clear();
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
564 remainingAncestor.reset();
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
565
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
566 ASSERT_FALSE(db.IsExistingResource(*manager, c));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
567 ASSERT_TRUE(db.IsExistingResource(*manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
568 ASSERT_TRUE(db.IsExistingResource(*manager, b));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
569 ASSERT_EQ(2u, db.GetAllResourcesCount(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
570 db.DeleteResource(*output, *manager, a);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
571 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
572 ASSERT_FALSE(db.IsExistingResource(*manager, a));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
573 ASSERT_FALSE(db.IsExistingResource(*manager, b));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
574 ASSERT_FALSE(db.IsExistingResource(*manager, c));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
576 ASSERT_EQ(0u, deletedAttachments.size());
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
577 ASSERT_EQ(2u, deletedResources.size());
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
578 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
579 ASSERT_EQ(OrthancPluginResourceType_Study, deletedResources["study"]);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
580 ASSERT_FALSE(remainingAncestor.get() != NULL);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
581
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
582 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
583 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount(*manager));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
584 int64_t p1 = db.CreateResource(*manager, "patient1", OrthancPluginResourceType_Patient);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
585 int64_t p2 = db.CreateResource(*manager, "patient2", OrthancPluginResourceType_Patient);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
586 int64_t p3 = db.CreateResource(*manager, "patient3", OrthancPluginResourceType_Patient);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
587 ASSERT_EQ(3u, db.GetUnprotectedPatientsCount(*manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 int64_t r;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
589 ASSERT_TRUE(db.SelectPatientToRecycle(r, *manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 ASSERT_EQ(p1, r);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
591 ASSERT_TRUE(db.SelectPatientToRecycle(r, *manager, p1));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 ASSERT_EQ(p2, r);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
593 ASSERT_FALSE(db.IsProtectedPatient(*manager, p1));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
594 db.SetProtectedPatient(*manager, p1, true);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
595 ASSERT_TRUE(db.IsProtectedPatient(*manager, p1));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
596 ASSERT_TRUE(db.SelectPatientToRecycle(r, *manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 ASSERT_EQ(p2, r);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
598 db.SetProtectedPatient(*manager, p1, false);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
599 ASSERT_FALSE(db.IsProtectedPatient(*manager, p1));
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
600 ASSERT_TRUE(db.SelectPatientToRecycle(r, *manager));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 ASSERT_EQ(p2, r);
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
602 db.DeleteResource(*output, *manager, p2);
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
603 ASSERT_TRUE(db.SelectPatientToRecycle(r, *manager, p3));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 ASSERT_EQ(p1, r);
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
605
288
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
606 {
289
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
607 // Test creating a large property of 16MB (large properties are
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
608 // notably necessary to serialize jobs)
288
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
609 // https://groups.google.com/g/orthanc-users/c/1Y3nTBdr0uE/m/K7PA5pboAgAJ
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
610 std::string longProperty;
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
611 longProperty.resize(16 * 1024 * 1024);
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
612 for (size_t i = 0; i < longProperty.size(); i++)
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
613 {
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
614 longProperty[i] = 'A' + (i % 26);
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
615 }
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
616
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
617 db.SetGlobalProperty(*manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal8, longProperty.c_str());
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
618
289
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
619 // The following line fails on MySQL 4.0 because the "value"
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
620 // column in "ServerProperties" is "TEXT" instead of "LONGTEXT"
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
621 db.SetGlobalProperty(*manager, "some-server", Orthanc::GlobalProperty_DatabaseInternal8, longProperty.c_str());
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
622
288
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
623 std::string tmp;
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
624 ASSERT_TRUE(db.LookupGlobalProperty(tmp, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal8));
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
625 ASSERT_EQ(longProperty, tmp);
289
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
626
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
627 tmp.clear();
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
628 ASSERT_TRUE(db.LookupGlobalProperty(tmp, *manager, "some-server", Orthanc::GlobalProperty_DatabaseInternal8));
0868500060f3 Fix serialization of large jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
629 ASSERT_EQ(longProperty, tmp);
288
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
630 }
6d4d413a8797 unit test for large properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
631
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
632 db.DeleteResource(*output, *manager, p1);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
633 db.DeleteResource(*output, *manager, p3);
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
634
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
635 for (size_t level = 0; level < 4; level++)
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
636 {
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
637 for (size_t attachmentLevel = 0; attachmentLevel < 4; attachmentLevel++)
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
638 {
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
639 // Test cascade up to the "patient" level
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
640 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
641
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
642 std::vector<int64_t> resources;
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
643 resources.push_back(db.CreateResource(*manager, "patient", OrthancPluginResourceType_Patient));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
644 resources.push_back(db.CreateResource(*manager, "study", OrthancPluginResourceType_Study));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
645 resources.push_back(db.CreateResource(*manager, "series", OrthancPluginResourceType_Series));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
646 resources.push_back(db.CreateResource(*manager, "instance", OrthancPluginResourceType_Instance));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
647
321
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
648 OrthancPluginAttachment d;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
649 d.uuid = "attachment";
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
650 d.contentType = Orthanc::FileContentType_DicomAsJson;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
651 d.uncompressedSize = 4242;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
652 d.uncompressedHash = "md5";
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
653 d.compressionType = Orthanc::CompressionType_None;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
654 d.compressedSize = 4242;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
655 d.compressedHash = "md5";
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
656 db.AddAttachment(*manager, resources[attachmentLevel], d, 42);
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
657
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
658 db.AttachChild(*manager, resources[0], resources[1]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
659 db.AttachChild(*manager, resources[1], resources[2]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
660 db.AttachChild(*manager, resources[2], resources[3]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
661 ASSERT_EQ(4u, db.GetAllResourcesCount(*manager));
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
662
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
663 deletedAttachments.clear();
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
664 deletedResources.clear();
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
665 remainingAncestor.reset();
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
666
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
667 db.DeleteResource(*output, *manager, resources[level]);
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
668
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
669 ASSERT_EQ(1u, deletedAttachments.size());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
670 ASSERT_EQ("attachment", *deletedAttachments.begin());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
671 ASSERT_EQ(4u, deletedResources.size());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
672 ASSERT_EQ(OrthancPluginResourceType_Patient, deletedResources["patient"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
673 ASSERT_EQ(OrthancPluginResourceType_Study, deletedResources["study"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
674 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
675 ASSERT_EQ(OrthancPluginResourceType_Instance, deletedResources["instance"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
676 ASSERT_TRUE(remainingAncestor.get() == NULL);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
677 }
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
678 }
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
679
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
680 for (size_t level = 1; level < 4; level++)
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
681 {
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
682 for (size_t attachmentLevel = 0; attachmentLevel < 4; attachmentLevel++)
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
683 {
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
684 // Test remaining ancestor
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
685 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
686
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
687 std::vector<int64_t> resources;
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
688 resources.push_back(db.CreateResource(*manager, "patient", OrthancPluginResourceType_Patient));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
689 resources.push_back(db.CreateResource(*manager, "study", OrthancPluginResourceType_Study));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
690 resources.push_back(db.CreateResource(*manager, "series", OrthancPluginResourceType_Series));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
691 resources.push_back(db.CreateResource(*manager, "instance", OrthancPluginResourceType_Instance));
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
692
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
693 int64_t unrelated = db.CreateResource(*manager, "unrelated", OrthancPluginResourceType_Patient);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
694 int64_t remaining = db.CreateResource(*manager, "remaining", static_cast<OrthancPluginResourceType>(level));
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
695
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
696 db.AttachChild(*manager, resources[0], resources[1]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
697 db.AttachChild(*manager, resources[1], resources[2]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
698 db.AttachChild(*manager, resources[2], resources[3]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
699 db.AttachChild(*manager, resources[level - 1], remaining);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
700 ASSERT_EQ(6u, db.GetAllResourcesCount(*manager));
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
701
321
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
702 OrthancPluginAttachment d;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
703 d.uuid = "attachment";
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
704 d.contentType = Orthanc::FileContentType_DicomAsJson;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
705 d.uncompressedSize = 4242;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
706 d.uncompressedHash = "md5";
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
707 d.compressionType = Orthanc::CompressionType_None;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
708 d.compressedSize = 4242;
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
709 d.compressedHash = "md5";
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
710 db.AddAttachment(*manager, resources[attachmentLevel], d, 42);
314
64763998cdff clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 313
diff changeset
711
313
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
712 deletedAttachments.clear();
321
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
713 d.uuid = "attachment2";
313
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
714 db.DeleteAttachment(*output, *manager, resources[attachmentLevel], Orthanc::FileContentType_DicomAsJson);
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
715 ASSERT_EQ(1u, deletedAttachments.size());
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
716 ASSERT_EQ("attachment", *deletedAttachments.begin());
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
717
321
eb0b04c10bc4 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 319
diff changeset
718 db.AddAttachment(*manager, resources[attachmentLevel], d, 43);
313
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
719
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
720 deletedAttachments.clear();
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
721 deletedResources.clear();
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
722 remainingAncestor.reset();
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
723
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
724 db.DeleteResource(*output, *manager, resources[3]); // delete instance
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
725
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
726 if (attachmentLevel < level)
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
727 {
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
728 ASSERT_EQ(0u, deletedAttachments.size());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
729 }
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
730 else
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
731 {
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
732 ASSERT_EQ(1u, deletedAttachments.size());
313
8bb2eb006e21 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 312
diff changeset
733 ASSERT_EQ("attachment2", *deletedAttachments.begin());
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
734 }
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
735
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
736 ASSERT_EQ(OrthancPluginResourceType_Instance, deletedResources["instance"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
737
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
738 ASSERT_TRUE(remainingAncestor.get() != NULL);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
739
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
740 switch (level)
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
741 {
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
742 case 1:
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
743 ASSERT_EQ(3u, deletedResources.size());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
744 ASSERT_EQ(OrthancPluginResourceType_Study, deletedResources["study"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
745 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
746 ASSERT_EQ("patient", remainingAncestor->first);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
747 ASSERT_EQ(OrthancPluginResourceType_Patient, remainingAncestor->second);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
748 break;
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
749
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
750 case 2:
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
751 ASSERT_EQ(2u, deletedResources.size());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
752 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
753 ASSERT_EQ("study", remainingAncestor->first);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
754 ASSERT_EQ(OrthancPluginResourceType_Study, remainingAncestor->second);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
755 break;
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
756
312
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
757 case 3:
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
758 ASSERT_EQ(1u, deletedResources.size());
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
759 ASSERT_EQ("series", remainingAncestor->first);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
760 ASSERT_EQ(OrthancPluginResourceType_Series, remainingAncestor->second);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
761 break;
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
762
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
763 default:
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
764 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
765 }
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
766
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
767 db.DeleteResource(*output, *manager, resources[0]);
117cf247c086 added unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
768 db.DeleteResource(*output, *manager, unrelated);
307
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
769 }
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
770 }
8de3a1ecac11 MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 301
diff changeset
771
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
772 manager->Close();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 }