Mercurial > hg > orthanc
diff UnitTestsSources/LuaTests.cpp @ 1051:92f4bf2c5d73
HTTP GET in Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Jul 2014 12:59:28 +0200 |
parents | 1b1d51e9f1a2 |
children | cc4ff680e2a0 |
line wrap: on
line diff
--- a/UnitTestsSources/LuaTests.cpp Wed Jul 23 11:36:35 2014 +0200 +++ b/UnitTestsSources/LuaTests.cpp Wed Jul 23 12:59:28 2014 +0200 @@ -33,10 +33,15 @@ #include "PrecompiledHeadersUnitTests.h" #include "gtest/gtest.h" +#include "../Core/Toolbox.h" #include "../Core/Lua/LuaFunctionCall.h" #include <boost/lexical_cast.hpp> +#if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) +#error "Please set UNIT_TESTS_WITH_HTTP_CONNEXIONS" +#endif + TEST(Lua, Json) { @@ -232,3 +237,23 @@ ASSERT_EQ("test2", v["List"][1][2].asString()); } } + +TEST(Lua, Http) +{ + const std::string url("http://orthanc.googlecode.com/hg/Resources/Configuration.json"); + + Orthanc::LuaContext lua; + std::string s; + lua.Execute(s, "print(HttpGet({}))"); + ASSERT_EQ("ERROR", Orthanc::Toolbox::StripSpaces(s)); + +#if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 + lua.Execute(s, "print(string.len(HttpGet(\"" + url + "\")))"); + ASSERT_LE(1000, boost::lexical_cast<int>(Orthanc::Toolbox::StripSpaces(s))); + + // Parse a JSON file + lua.Execute(s, "print(HttpGet(\"" + url + "\", true)['Name'])"); + ASSERT_EQ("MyOrthanc", Orthanc::Toolbox::StripSpaces(s)); +#endif + +}