Guest User

Untitled

a guest
Jul 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. /*
  2. Copyright (c) 2010, The Mineserver Project
  3. All rights reserved.
  4.  
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of the The Mineserver Project nor the
  13. names of its contributors may be used to endorse or promote products
  14. derived from this software without specific prior written permission.
  15.  
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  20. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27.  
  28. /*
  29. This expects config.cfg to be with the test program.
  30. The config.cfg needs at least the following defined:
  31. * system.server_name to "Mineserver alpha testserver"
  32. * net.port should be 25565
  33. * system.user_validation = false
  34. * system.physics.enabled = true
  35. * system.something= 13.37;
  36. Consider getting the test runner to generate a test.cfg at the start.
  37. */
  38. #include "catch/catch.hpp"
  39.  
  40. #include "../src/config.h"
  41.  
  42. TEST_CASE( "config/loading", "Can a config file be loaded" )
  43. {
  44. Config config;
  45. REQUIRE( config.load("config.cfg") == true );
  46. config.dump();
  47. }
  48.  
  49. TEST_CASE( "config/loading", "Loading non-existant file" )
  50. {
  51. Config config;
  52. REQUIRE( config.load("this-file_does_not_exist.cfg") == false );
  53. }
  54.  
  55. TEST_CASE( "config/has=true", "")
  56. {
  57. Config config;
  58. REQUIRE( config.load("config.cfg") == true );
  59. REQUIRE( config.has("system.server_name") == true );
  60. }
  61.  
  62. TEST_CASE( "config/has=false", "" )
  63. {
  64. Config config;
  65. REQUIRE( config.load("config.cfg") == true );
  66. REQUIRE( config.has("system.this_key_does_not_exist") == false );
  67. }
  68.  
  69. TEST_CASE( "config/sData", "" )
  70. {
  71. Config config;
  72. REQUIRE( config.load("config.cfg") == true );
  73. REQUIRE( config.sData("system.server_name") == std::string("Mineserver alpha testserver") );
  74. }
  75.  
  76. TEST_CASE( "config/str2int", "Attempt to extract integer from a string" )
  77. {
  78. Config config;
  79. REQUIRE( config.load("config.cfg") == true );
  80. REQUIRE( config.iData("system.server_name") == 0);
  81. }
  82.  
  83. TEST_CASE( "config/str2double", "Attempt to extract double from a string" )
  84. {
  85. Config config;
  86. REQUIRE( config.load("config.cfg") == true );
  87. REQUIRE( config.iData("system.server_name") == 0.0);
  88. }
  89.  
  90. TEST_CASE( "config/str2float", "Attempt to extract float from a string" )
  91. {
  92. Config config;
  93. REQUIRE( config.load("config.cfg") == true );
  94. REQUIRE( config.iData("system.server_name") == 0.0f);
  95. }
  96.  
  97. TEST_CASE( "config/str2long", "Attempt to extract long from a string" )
  98. {
  99. Config config;
  100. REQUIRE( config.load("config.cfg") == true );
  101. REQUIRE( config.iData("system.server_name") == 0L);
  102. }
  103.  
  104. TEST_CASE( "config/str2bool", "Attempt to extract boolean from a string" )
  105. {
  106. Config config;
  107. REQUIRE( config.load("config.cfg") == true );
  108. REQUIRE( config.bData("system.server_name") == false);
  109. }
  110.  
  111. TEST_CASE( "config/boolean=true", "Read true value from boolean" )
  112. {
  113. Config config;
  114. REQUIRE( config.load("config.cfg") == true );
  115. REQUIRE( config.has("system.physics.enabled") == true);
  116. REQUIRE( config.bData("system.physics.enabled") == true);
  117. }
  118.  
  119. TEST_CASE( "config/boolean=false", "Read false value from boolean" )
  120. {
  121. Config config;
  122. REQUIRE( config.load("config.cfg") == true );
  123. REQUIRE( config.bData("system.user_validation") == false);
  124. }
  125.  
  126. TEST_CASE( "config/port=25565", "Check integer value" )
  127. {
  128. Config config;
  129. REQUIRE( config.load("config.cfg") == true );
  130. REQUIRE( config.iData("net.port") == 25565);
  131. }
  132.  
  133. TEST_CASE( "config/port=25565", "Check integer as float value" )
  134. {
  135. Config config;
  136. REQUIRE( config.load("config.cfg") == true );
  137. REQUIRE( config.fData("net.port") == 25565.0f);
  138. }
  139.  
  140. TEST_CASE( "config/port=25565", "Check integer as double value" )
  141. {
  142. Config config;
  143. REQUIRE( config.load("config.cfg") == true );
  144. REQUIRE( config.dData("net.port") == 25565.0);
  145. }
  146.  
  147. TEST_CASE( "config/port=25565", "Check integer as long value" )
  148. {
  149. Config config;
  150. REQUIRE( config.load("config.cfg") == true );
  151. REQUIRE( config.lData("net.port") == 25565L);
  152. }
  153.  
  154. TEST_CASE( "config/something=13.37", "Check double value" )
  155. {
  156. Config config;
  157. REQUIRE( config.load("config.cfg") == true );
  158. REQUIRE( config.dData("system.something") == 13.37);
  159. }
  160.  
  161. TEST_CASE( "config/something=13.37", "Check double as int value" )
  162. {
  163. Config config;
  164. REQUIRE( config.load("config.cfg") == true );
  165. REQUIRE( config.iData("system.something") == 13);
  166. }
  167.  
  168. TEST_CASE( "config/something=13.37", "Check double as long value" )
  169. {
  170. Config config;
  171. REQUIRE( config.load("config.cfg") == true );
  172. REQUIRE( config.lData("system.something") == 13L);
  173. }
Add Comment
Please, Sign In to add comment