1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
/// @file test_request.cc
/// @date Jul 2024
/// @author Emanuele Danovaro
#include "eckit/log/JSON.h"
#include "eckit/types/Date.h"
#include "metkit/mars/MarsExpansion.h"
#include "metkit/mars/MarsLanguage.h"
#include "metkit/mars/MarsParser.h"
#include "metkit/mars/MarsRequest.h"
#include "metkit/mars/Type.h"
#include "eckit/testing/Test.h"
#include "eckit/utils/Tokenizer.h"
using namespace eckit::testing;
namespace metkit {
namespace mars {
namespace test {
//-----------------------------------------------------------------------------
CASE("test_request_json") {
{
const char* text =
"retrieve,class=od,expver=0079,stream=enfh,date=20240729,time=00/"
"12,type=fcmean,levtype=sfc,step=24,number=1/to/2,param=mucin/mucape/tprate";
MarsRequest r = MarsRequest::parse(text);
{
std::stringstream ss;
eckit::JSON plain(ss);
r.json(plain);
EXPECT_EQUAL(ss.str(),
"{\"class\":\"od\",\"expver\":\"0079\",\"stream\":\"enfh\",\"date\":\"20240729\",\"time\":["
"\"0000\",\"1200\"],\"type\":\"fcmean\",\"levtype\":\"sfc\",\"step\":\"24\",\"number\":[\"1\","
"\"2\"],\"param\":[\"228236\",\"228235\",\"172228\"],\"domain\":\"g\",\"repres\":\"sh\"}");
}
{
std::stringstream ss;
eckit::JSON array(ss);
r.json(array, true);
EXPECT_EQUAL(
ss.str(),
"{\"class\":\"od\",\"expver\":\"0079\",\"stream\":\"enfh\",\"date\":[\"20240729\"],\"time\":["
"\"0000\",\"1200\"],\"type\":\"fcmean\",\"levtype\":\"sfc\",\"step\":[\"24\"],\"number\":["
"\"1\",\"2\"],\"param\":[\"228236\",\"228235\",\"172228\"],\"domain\":\"g\",\"repres\":\"sh\"}");
}
}
{
const char* text =
"retrieve,class=od,expver=1,stream=wave,date=20240729,time=00,type=an,levtype=sfc,step=24,param=2dfd ";
MarsRequest r = MarsRequest::parse(text);
{
std::stringstream ss;
eckit::JSON plain(ss);
r.json(plain);
EXPECT_EQUAL(
ss.str(),
"{\"class\":\"od\",\"expver\":\"0001\",\"stream\":\"wave\",\"date\":\"20240729\",\"time\":\"0000\","
"\"type\":\"an\",\"levtype\":\"sfc\",\"step\":\"24\",\"param\":\"140251\",\"domain\":\"g\",\"repres\":"
"\"sh\"}");
}
{
std::stringstream ss;
eckit::JSON array(ss);
r.json(array, true);
EXPECT_EQUAL(
ss.str(),
"{\"class\":\"od\",\"expver\":\"0001\",\"stream\":\"wave\",\"date\":[\"20240729\"],\"time\":[\"0000\"],"
"\"type\":\"an\",\"levtype\":\"sfc\",\"step\":[\"24\"],\"param\":[\"140251\"],\"domain\":\"g\","
"\"repres\":\"sh\"}");
}
}
}
//-----------------------------------------------------------------------------
} // namespace test
} // namespace mars
} // namespace metkit
int main(int argc, char** argv) {
return run_tests(argc, argv);
}
|