Updated test

This commit is contained in:
emeric
2025-11-16 20:56:55 +01:00
parent 106c30a293
commit 162d910904
3 changed files with 26 additions and 11 deletions
@@ -21,6 +21,9 @@
#include <gtest/gtest.h>
#include "core/String.hpp"
#include "core/Version.hpp"
#include "ProtocolVersion.hpp"
#include "SubsonicResponse.hpp"
@@ -58,12 +61,15 @@ namespace lms::api::subsonic::tests
TEST(SubsonicResponse, emptyJson)
{
Response response{ Response::createOkResponse(ProtocolVersion{ 1, 16, 0 }) };
Response response{ Response::createOkResponse(defaultServerProtocolVersion) };
std::ostringstream oss;
response.write(oss, ResponseFormat::json);
EXPECT_EQ(oss.str(), R"({"subsonic-response":{"openSubsonic":true,"serverVersion":"v3.72.0","status":"ok","type":"lms","version":"1.16.0"}})");
std::string expected{ R"({"subsonic-response":{"openSubsonic":true,"serverVersion":"${VERSION}","status":"ok","type":"lms","version":"1.16.1"}})" };
expected = core::stringUtils::replaceInString(expected, "${VERSION}", core::getVersion());
EXPECT_EQ(oss.str(), expected);
}
TEST(SubsonicResponse, json)
@@ -73,18 +79,24 @@ namespace lms::api::subsonic::tests
std::ostringstream oss;
response.write(oss, ResponseFormat::json);
EXPECT_EQ(oss.str(), R"({"subsonic-response":{"openSubsonic":true,"serverVersion":"v3.72.0","status":"ok","type":"lms","version":"1.16.0","MyNode":{"Attr1":"value1","Attr2":"value2","attr3":"<value3=\"foo\">","attr4":true,"attr5":false,"attr6":3.14159,"attr7":333666,"MyArrayChild":[{"Attr42":0},{"Attr42":1}],"MyArray1":["value1","value2","value1","value2"],"MyArray2":[0]}}})");
std::string expected{ R"({"subsonic-response":{"openSubsonic":true,"serverVersion":"${VERSION}","status":"ok","type":"lms","version":"1.16.1","MyNode":{"Attr1":"value1","Attr2":"value2","attr3":"<value3=\"foo\">","attr4":true,"attr5":false,"attr6":3.14159,"attr7":333666,"MyArrayChild":[{"Attr42":0},{"Attr42":1}],"MyArray1":["value1","value2","value1","value2"],"MyArray2":[0]}}})" };
expected = core::stringUtils::replaceInString(expected, "${VERSION}", core::getVersion());
EXPECT_EQ(oss.str(), expected);
}
TEST(SubsonicResponse, emptyXml)
{
Response response{ Response::createOkResponse(ProtocolVersion{ 1, 16, 0 }) };
Response response{ Response::createOkResponse(defaultServerProtocolVersion) };
std::ostringstream oss;
response.write(oss, ResponseFormat::xml);
EXPECT_EQ(oss.str(), R"(<?xml version="1.0" encoding="utf-8"?>
<subsonic-response openSubsonic="true" serverVersion="v3.72.0" status="ok" type="lms" version="1.16.0" xmlns="http://subsonic.org/restapi"/>)");
std::string expected{ R"(<?xml version="1.0" encoding="utf-8"?>
<subsonic-response openSubsonic="true" serverVersion="${VERSION}" status="ok" type="lms" version="1.16.1" xmlns="http://subsonic.org/restapi"/>)" };
expected = core::stringUtils::replaceInString(expected, "${VERSION}", core::getVersion());
EXPECT_EQ(oss.str(), expected);
}
TEST(SubsonicResponse, xml)
@@ -94,8 +106,11 @@ namespace lms::api::subsonic::tests
std::ostringstream oss;
response.write(oss, ResponseFormat::xml);
EXPECT_EQ(oss.str(), R"(<?xml version="1.0" encoding="utf-8"?>
<subsonic-response openSubsonic="true" serverVersion="v3.72.0" status="ok" type="lms" version="1.16.0" xmlns="http://subsonic.org/restapi"><MyNode Attr1="value1" Attr2="value2" attr3="&lt;value3=&quot;foo&quot;&gt;" attr4="true" attr5="false" attr6="3.14159" attr7="333666"><MyArrayChild Attr42="0"/><MyArrayChild Attr42="1"/><MyArray1>value1</MyArray1><MyArray1>value2</MyArray1><MyArray1>value1</MyArray1><MyArray1>value2</MyArray1><MyArray2>0</MyArray2></MyNode></subsonic-response>)");
std::string expected{ R"(<?xml version="1.0" encoding="utf-8"?>
<subsonic-response openSubsonic="true" serverVersion="${VERSION}" status="ok" type="lms" version="1.16.1" xmlns="http://subsonic.org/restapi"><MyNode Attr1="value1" Attr2="value2" attr3="&lt;value3=&quot;foo&quot;&gt;" attr4="true" attr5="false" attr6="3.14159" attr7="333666"><MyArrayChild Attr42="0"/><MyArrayChild Attr42="1"/><MyArray1>value1</MyArray1><MyArray1>value2</MyArray1><MyArray1>value1</MyArray1><MyArray1>value2</MyArray1><MyArray2>0</MyArray2></MyNode></subsonic-response>)" };
expected = core::stringUtils::replaceInString(expected, "${VERSION}", core::getVersion());
EXPECT_EQ(oss.str(), expected);
}
} // namespace lms::api::subsonic::tests