Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkShaderRepositoryTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkIShaderRepository.h"
18 
19 #include "usGetModuleContext.h"
20 #include "usModuleContext.h"
21 #include "usServiceReference.h"
22 
23 #include "mitkTestingMacros.h"
24 
25 #include <sstream>
26 
27 int mitkShaderRepositoryTest(int /*argc*/, char * /*argv*/ [])
28 {
29  MITK_TEST_BEGIN("ShaderRepository")
30 
31  us::ModuleContext *context = us::GetModuleContext();
32  us::ServiceReference<mitk::IShaderRepository> serviceRef = context->GetServiceReference<mitk::IShaderRepository>();
33  MITK_TEST_CONDITION_REQUIRED(serviceRef, "IShaderRepository service ref")
34 
35  mitk::IShaderRepository *shaderRepo = context->GetService(serviceRef);
36  MITK_TEST_CONDITION_REQUIRED(shaderRepo, "Check non-empty IShaderRepositry")
37 
38  mitk::IShaderRepository::Shader::Pointer shader = shaderRepo->GetShader("mitkShaderLighting");
39  MITK_TEST_CONDITION_REQUIRED(shader.IsNotNull(), "Non-null mitkShaderLighting shader")
40 
41  MITK_TEST_CONDITION(shader->GetName() == "mitkShaderLighting", "Shader name")
42  MITK_TEST_CONDITION(!shader->GetMaterialXml().empty(), "Shader content")
43 
44  const std::string testShader =
45  "<Material name=\"SmoothPlastic\" number_of_properties=\"1\" number_of_vertex_shaders=\"0\" "
46  "number_of_fragment_shaders=\"0\">"
47  "<Property name=\"ShinyProperty\">"
48  "<Member name=\"DiffuseColor\" number_of_elements=\"3\" type=\"Double\" value=\"1.0 0.0 0.0\"/>"
49  "</Property>"
50  "</Material>";
51 
52  const std::size_t shaderCount = shaderRepo->GetShaders().size();
53 
54  std::stringstream testShaderStream(testShader);
55  const std::string testShaderName = "SmoothPlastic";
56  int id = shaderRepo->LoadShader(testShaderStream, testShaderName);
57  MITK_TEST_CONDITION_REQUIRED(id > -1, "New shader id")
58  MITK_TEST_CONDITION(shaderRepo->GetShaders().size() == shaderCount + 1, "Shader count")
59  mitk::IShaderRepository::Shader::Pointer shader2 = shaderRepo->GetShader(testShaderName);
60  MITK_TEST_CONDITION_REQUIRED(shader2.IsNotNull(), "Non-null shader")
61  MITK_TEST_CONDITION(shader2->GetId() == id, "Shader id")
62  MITK_TEST_CONDITION(shader2->GetName() == testShaderName, "Shader name")
63  mitk::IShaderRepository::Shader::Pointer shader3 = shaderRepo->GetShader(id);
64  MITK_TEST_CONDITION_REQUIRED(shader3.IsNotNull(), "Non-null shader")
65  MITK_TEST_CONDITION(shader3->GetId() == id, "Shader id")
66  MITK_TEST_CONDITION(shader3->GetName() == testShaderName, "Shader name")
67 
68  MITK_TEST_CONDITION_REQUIRED(shaderRepo->UnloadShader(id), "Unload shader")
69  MITK_TEST_CONDITION(shaderRepo->GetShader(testShaderName).IsNull(), "Null shader")
70  MITK_TEST_CONDITION(shaderRepo->GetShader(id).IsNull(), "Null shader")
71 
73 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Management class for vtkShader XML descriptions.
#define MITK_TEST_CONDITION(COND, MSG)
and MITK_TEST_END()
int mitkShaderRepositoryTest(int, char *[])
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.