Documentation for OpenFLUID 2.2.0
SignatureCommon.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file SignatureCommon.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inrae.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_WARESDEVTESTS_SIGNATURECOMMON_HPP__
41 #define __OPENFLUID_WARESDEVTESTS_SIGNATURECOMMON_HPP__
42 
43 
45 {
46  BOOST_CHECK_EQUAL(S1.Title,S2.Title);
47  BOOST_CHECK_EQUAL(S1.Description,S2.Description);
48  BOOST_CHECK_EQUAL_COLLECTIONS(S1.Tags.begin(),S1.Tags.end(),S2.Tags.begin(),S2.Tags.end());
49  BOOST_CHECK_EQUAL(S1.Creator,S2.Creator);
50  BOOST_CHECK(S1.CreatedAt == S2.CreatedAt);
51  BOOST_CHECK_EQUAL(S1.IsOpen,S2.IsOpen);
52 }
53 
54 
55 // =====================================================================
56 // =====================================================================
57 
58 
60 {
61  openfluid::thirdparty::json TagsArr1 = Issue1.value("tags",openfluid::thirdparty::json::array());
62  openfluid::thirdparty::json TagsArr2 = Issue2.value("tags",openfluid::thirdparty::json::array());
63  BOOST_REQUIRE_EQUAL(TagsArr1.size(), TagsArr2.size());
64 
65  BOOST_CHECK_EQUAL(Issue1.value("id", 0), Issue2.value("id", 0));
66  BOOST_CHECK_EQUAL(Issue1.value("title", ""), Issue2.value("title", ""));
67  BOOST_CHECK_EQUAL(Issue1.value("description", ""), Issue2.value("description", ""));
68  for (unsigned int i=0; i < TagsArr1.size(); i++)
69  {
70  BOOST_CHECK_EQUAL(TagsArr1[i], TagsArr2[i]);
71  }
72  BOOST_CHECK_EQUAL(Issue1.value("creator", ""), Issue2.value("creator", ""));
73  BOOST_CHECK_EQUAL(Issue1.value("created_at", ""), Issue2.value("created_at", ""));
74  BOOST_CHECK_EQUAL(Issue1.value("updated_at", ""), Issue2.value("updated_at", ""));
75  BOOST_CHECK_EQUAL(Issue1.value("state", ""), Issue2.value("state", ""));
76 
77 }
78 
79 
80 // =====================================================================
81 // =====================================================================
82 
83 
85 {
86  BOOST_CHECK(Json1.is_array());
87  BOOST_CHECK(Json2.is_array());
88  BOOST_REQUIRE_EQUAL(Json1.size(), Json2.size());
89 }
90 
91 
92 // =====================================================================
93 // =====================================================================
94 
95 
96 template<typename SignatureType>
97 void compareSignaturesBase(const SignatureType& Sign1,const SignatureType& Sign2)
98 {
99  BOOST_CHECK_EQUAL(Sign1.ID,Sign2.ID);
100  BOOST_CHECK_EQUAL(Sign1.Name,Sign2.Name);
101  BOOST_CHECK_EQUAL(Sign1.Description,Sign2.Description);
102  BOOST_CHECK_EQUAL(Sign1.Status,Sign2.Status);
103  BOOST_CHECK_EQUAL(Sign1.Version,Sign2.Version);
104 
105  BOOST_REQUIRE_EQUAL(Sign1.Authors.size(),Sign2.Authors.size());
106  for (unsigned int i=0; i < Sign1.Authors.size(); i++)
107  {
108  BOOST_CHECK_EQUAL(Sign1.Authors[i].first,Sign2.Authors[i].first);
109  BOOST_CHECK_EQUAL(Sign1.Authors[i].second,Sign2.Authors[i].second);
110  }
111 
112  BOOST_REQUIRE_EQUAL(Sign1.Contacts.size(),Sign2.Contacts.size());
113  for (unsigned int i=0; i < Sign1.Contacts.size(); i++)
114  {
115  BOOST_CHECK_EQUAL(Sign1.Contacts[i].first,Sign2.Contacts[i].first);
116  BOOST_CHECK_EQUAL(Sign1.Contacts[i].second,Sign2.Contacts[i].second);
117  }
118 
119  BOOST_CHECK_EQUAL(Sign1.License,Sign2.License);
120 
121  BOOST_CHECK_EQUAL(Sign1.Tags.size(),Sign2.Tags.size());
122  BOOST_CHECK_EQUAL_COLLECTIONS(Sign1.Tags.begin(),Sign1.Tags.end(),Sign2.Tags.begin(),Sign2.Tags.end());
123 
124  BOOST_CHECK_EQUAL(Sign1.Links.size(),Sign2.Links.size());
125 
126  BOOST_REQUIRE_EQUAL(Sign1.Issues().size(),Sign2.Issues().size());
127  for (const auto& S1 : Sign1.Issues())
128  {
129  BOOST_REQUIRE_NO_THROW(Sign2.Issues.get(S1.first));
130  auto S2 = Sign2.Issues().at(S1.first);
131 
132  compareIssues(S1.second, S2);
133  }
134 
135  BOOST_REQUIRE_EQUAL(Sign1.Dependencies.size(),Sign2.Dependencies.size());
136  for (const auto& D : Sign1.Dependencies)
137  {
138  BOOST_REQUIRE_NO_THROW(Sign2.Dependencies.at(D.first));
139  BOOST_REQUIRE_EQUAL(D.second, Sign2.Dependencies.at(D.first));
140  }
141 }
142 
143 
144 // =====================================================================
145 // =====================================================================
146 
147 
149 {
150  BOOST_CHECK_EQUAL(Json1.value("id", ""), Json2.value("id", ""));
151  BOOST_CHECK_EQUAL(Json1.value("name", ""), Json2.value("name", ""));
152  BOOST_CHECK_EQUAL(Json1.value("description", ""), Json2.value("description", ""));
153  BOOST_CHECK_EQUAL(Json1.value("status", ""), Json2.value("status", ""));
154  BOOST_CHECK_EQUAL(Json1.value("version", ""), Json2.value("version", ""));
155 
156  openfluid::thirdparty::json AuthorsArr1 = Json1.value("authors",openfluid::thirdparty::json::array());
157  openfluid::thirdparty::json AuthorsArr2 = Json2.value("authors",openfluid::thirdparty::json::array());
158  checkArraysJSON(AuthorsArr1, AuthorsArr2);
159  for (unsigned int i=0; i < AuthorsArr1.size(); i++)
160  {
161  BOOST_CHECK_EQUAL(AuthorsArr1[i].value("name", ""), AuthorsArr1[i].value("name", ""));
162  BOOST_CHECK_EQUAL(AuthorsArr1[i].value("email", ""), AuthorsArr1[i].value("email", ""));
163  }
164 
165  openfluid::thirdparty::json ContactsArr1 = Json1.value("contacts",openfluid::thirdparty::json::array());
166  openfluid::thirdparty::json ContactsArr2 = Json2.value("contacts",openfluid::thirdparty::json::array());
167  checkArraysJSON(ContactsArr1, ContactsArr2);
168  for (unsigned int i=0; i < ContactsArr1.size(); i++)
169  {
170  BOOST_CHECK_EQUAL(ContactsArr1[i].value("name", ""), ContactsArr2[i].value("name", ""));
171  BOOST_CHECK_EQUAL(ContactsArr1[i].value("email", ""), ContactsArr2[i].value("email", ""));
172  }
173 
174  BOOST_CHECK_EQUAL(Json1.value("license", ""), Json2.value("license", ""));
175 
176  openfluid::thirdparty::json TagsArr1 = Json1.value("tags",openfluid::thirdparty::json::array());
177  openfluid::thirdparty::json TagsArr2 = Json2.value("tags",openfluid::thirdparty::json::array());
178  checkArraysJSON(TagsArr1, TagsArr2);
179  for (unsigned int i=0; i < TagsArr1.size(); i++)
180  {
181  BOOST_CHECK_EQUAL(TagsArr1[i], TagsArr2[i]);
182  }
183 
184  openfluid::thirdparty::json LinksArr1 = Json1.value("links",openfluid::thirdparty::json::array());
185  openfluid::thirdparty::json LinksArr2 = Json2.value("links",openfluid::thirdparty::json::array());
186  checkArraysJSON(LinksArr1, LinksArr2);
187  for (unsigned int i=0; i < LinksArr1.size(); i++)
188  {
189  BOOST_CHECK_EQUAL(LinksArr1[i].value("label", ""), LinksArr2[i].value("label", ""));
190  BOOST_CHECK_EQUAL(LinksArr1[i].value("url", ""), LinksArr2[i].value("url", ""));
191  }
192 
193  openfluid::thirdparty::json IssuesArr1 = Json1.value("issues", openfluid::thirdparty::json::array());
194  openfluid::thirdparty::json IssuesArr2 = Json2.value("issues", openfluid::thirdparty::json::array());
195  checkArraysJSON(IssuesArr1, IssuesArr2);
196  for (unsigned int i=0; i < IssuesArr1.size(); i++)
197  {
198  compareIssuesJSON(IssuesArr1[i], IssuesArr2[i]);
199  }
200 
201  openfluid::thirdparty::json Deps1 = Json1.value("dependencies", openfluid::thirdparty::json::array());
202  openfluid::thirdparty::json Deps2 = Json2.value("dependencies", openfluid::thirdparty::json::array());
203  // TOIMPL check dependencies
204 }
205 
206 
207 // =====================================================================
208 // =====================================================================
209 
210 
212 {
213  if(Json.is_object())
214  {
215  std::map<std::string, openfluid::thirdparty::json> orderedMapJSON;
216  for (auto& [key, value] : Json.items())
217  {
218  orderedMapJSON[key] = value;
219  }
220  for (auto& [key, value] : orderedMapJSON)
221  {
222  sortJson(value);
223  }
224  Json = openfluid::thirdparty::json(orderedMapJSON);
225  }
226 }
227 
228 
229 // =====================================================================
230 // =====================================================================
231 
232 
235  bool WithCheck = true)
236 {
237  bool IsEqual = true;
238 
239  sortJson(Json1);
240  sortJson(Json2);
241 
242  unsigned int Json1Size = Json1.size();
243  unsigned int Json2Size = Json2.size();
244  if(WithCheck)
245  {
246  BOOST_CHECK_EQUAL(Json1Size, Json2Size);
247  }
248  IsEqual = IsEqual && Json1Size == Json2Size;
249 
250  if(Json1.is_object() || Json2.is_object())
251  {
252  auto It2 = Json2.cbegin();
253  for (auto It1 = Json1.cbegin(); It1 != Json1.cend(); ++It1, ++It2)
254  {
255  if(WithCheck)
256  {
257  BOOST_CHECK_EQUAL(It1.key(), It2.key());
258  }
259  IsEqual = IsEqual && It1.key() == It2.key();
260  auto It1Value = It1.value();
261  auto It2Value = It2.value();
262  if(It1Value.is_primitive() || It2Value.is_primitive())
263  {
264  if(WithCheck)
265  {
266  BOOST_CHECK_EQUAL(It1Value, It2Value);
267  }
268  IsEqual = IsEqual && It1Value == It2Value;
269  }
270  else
271  {
272  IsEqual = IsEqual && compareJSONRecursive(It1Value, It2Value, WithCheck);
273  }
274  }
275  }
276  else if(Json1.is_array() || Json2.is_array())
277  {
278  auto It2 = Json2.cbegin();
279  for (auto It1 = Json1.cbegin(); It1 != Json1.cend(); ++It1, ++It2)
280  {
281  auto Child1 = *It1;
282  auto Child2 = *It2;
283  if(Child1.is_primitive() || Child2.is_primitive())
284  {
285  if(WithCheck)
286  {
287  BOOST_CHECK_EQUAL(Child1, Child2);
288  }
289  IsEqual = IsEqual && Child1 == Child2;
290  }
291  else
292  {
293  IsEqual = IsEqual && compareJSONRecursive(Child1, Child2, WithCheck);
294  }
295  }
296  }
297  else
298  {
299  if(WithCheck)
300  {
301  BOOST_CHECK_EQUAL(Json1, Json2);
302  }
303  IsEqual = IsEqual && Json1 == Json2;
304  }
305 
306  return IsEqual;
307 }
308 
309 #endif /* __OPENFLUID_WARESDEVTESTS_SIGNATURECOMMON_HPP__ */
void sortJson(openfluid::thirdparty::json &Json)
Definition: SignatureCommon.hpp:211
void compareSignaturesBase(const SignatureType &Sign1, const SignatureType &Sign2)
Definition: SignatureCommon.hpp:97
void compareJSONBase(const openfluid::thirdparty::json &Json1, const openfluid::thirdparty::json &Json2)
Definition: SignatureCommon.hpp:148
void compareIssues(const openfluid::ware::WareIssue S1, openfluid::ware::WareIssue S2)
Definition: SignatureCommon.hpp:44
void checkArraysJSON(const openfluid::thirdparty::json &Json1, const openfluid::thirdparty::json &Json2)
Definition: SignatureCommon.hpp:84
void compareIssuesJSON(const openfluid::thirdparty::json &Issue1, const openfluid::thirdparty::json &Issue2)
Definition: SignatureCommon.hpp:59
bool compareJSONRecursive(openfluid::thirdparty::json &Json1, openfluid::thirdparty::json &Json2, bool WithCheck=true)
Definition: SignatureCommon.hpp:233
Definition: WareIssues.hpp:60
std::string Title
Definition: WareIssues.hpp:65
std::string Description
Definition: WareIssues.hpp:67
openfluid::core::DateTime CreatedAt
Definition: WareIssues.hpp:73
std::string Creator
Definition: WareIssues.hpp:71
bool IsOpen
Definition: WareIssues.hpp:77
std::vector< std::string > Tags
Definition: WareIssues.hpp:69
nlohmann::ordered_json json
Definition: JSON.hpp:52