changeset 712:9e3f21441903

lua tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Feb 2014 16:16:07 +0100
parents 8f62e8d5a384
children 9d1973813d8b
files UnitTestsSources/FileStorage.cpp UnitTestsSources/Lua.cpp
diffstat 2 files changed, 78 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/UnitTestsSources/FileStorage.cpp	Thu Feb 13 15:51:10 2014 +0100
+++ b/UnitTestsSources/FileStorage.cpp	Thu Feb 13 16:16:07 2014 +0100
@@ -15,6 +15,16 @@
 
 using namespace Orthanc;
 
+
+static void StringToVector(std::vector<uint8_t>& v,
+                           const std::string& s)
+{
+  v.resize(s.size());
+  for (size_t i = 0; i < s.size(); i++)
+    v[i] = s[i];
+}
+
+
 TEST(FileStorage, Basic)
 {
   FileStorage s("FileStorageUnitTests");
@@ -25,6 +35,21 @@
   s.ReadFile(d, uid);
   ASSERT_EQ(d.size(), data.size());
   ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
+  ASSERT_EQ(s.GetCompressedSize(uid), data.size());
+}
+
+TEST(FileStorage, Basic2)
+{
+  FileStorage s("FileStorageUnitTests");
+
+  std::vector<uint8_t> data;
+  StringToVector(data, Toolbox::GenerateUuid());
+  std::string uid = s.Create(data);
+  std::string d;
+  s.ReadFile(d, uid);
+  ASSERT_EQ(d.size(), data.size());
+  ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
+  ASSERT_EQ(s.GetCompressedSize(uid), data.size());
 }
 
 TEST(FileStorage, EndToEnd)
@@ -99,6 +124,27 @@
 }
 
 
+TEST(FileStorageAccessor, NoCompression2)
+{
+  FileStorage s("FileStorageUnitTests");
+  CompressedFileStorageAccessor accessor(s);
+
+  accessor.SetCompressionForNextOperations(CompressionType_None);
+  std::vector<uint8_t> data;
+  StringToVector(data, "Hello world");
+  FileInfo info = accessor.Write(data, FileContentType_Dicom);
+  
+  std::string r;
+  accessor.Read(r, info.GetUuid());
+
+  ASSERT_EQ(0, memcmp(&r[0], &data[0], data.size()));
+  ASSERT_EQ(CompressionType_None, info.GetCompressionType());
+  ASSERT_EQ(11u, info.GetUncompressedSize());
+  ASSERT_EQ(11u, info.GetCompressedSize());
+  ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
+}
+
+
 TEST(FileStorageAccessor, Compression)
 {
   FileStorage s("FileStorageUnitTests");
--- a/UnitTestsSources/Lua.cpp	Thu Feb 13 15:51:10 2014 +0100
+++ b/UnitTestsSources/Lua.cpp	Thu Feb 13 16:16:07 2014 +0100
@@ -3,7 +3,7 @@
 #include "../Core/Lua/LuaFunctionCall.h"
 
 
-TEST(Lua, Simple)
+TEST(Lua, Json)
 {
   Orthanc::LuaContext lua;
   lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
@@ -70,3 +70,34 @@
   ASSERT_FALSE(lua.IsExistingFunction("a"));
   ASSERT_FALSE(lua.IsExistingFunction("Dummy"));
 }
+
+
+TEST(Lua, Simple)
+{
+  Orthanc::LuaContext lua;
+  lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
+
+  {
+    Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
+    f.PushString("hello");
+    f.Execute();
+  }
+
+  {
+    Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
+    f.PushBoolean(true);
+    f.Execute();
+  }
+
+  {
+    Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
+    f.PushInteger(42);
+    f.Execute();
+  }
+
+  {
+    Orthanc::LuaFunctionCall f(lua, "PrintRecursive");
+    f.PushDouble(3.1415);
+    f.Execute();
+  }
+}