lldir_test.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /**
  2.  * @file lldir_test.cpp
  3.  * @date 2008-05
  4.  * @brief LLDir test cases.
  5.  *
  6.  * $LicenseInfo:firstyear=2008&license=viewergpl$
  7.  * 
  8.  * Copyright (c) 2008-2010, Linden Research, Inc.
  9.  * 
  10.  * Second Life Viewer Source Code
  11.  * The source code in this file ("Source Code") is provided by Linden Lab
  12.  * to you under the terms of the GNU General Public License, version 2.0
  13.  * ("GPL"), unless you have obtained a separate licensing agreement
  14.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  15.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17.  * 
  18.  * There are special exceptions to the terms and conditions of the GPL as
  19.  * it is applied to this Source Code. View the full text of the exception
  20.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  21.  * online at
  22.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23.  * 
  24.  * By copying, modifying or distributing this software, you acknowledge
  25.  * that you have read and understood your obligations described above,
  26.  * and agree to abide by those obligations.
  27.  * 
  28.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30.  * COMPLETENESS OR PERFORMANCE.
  31.  * $/LicenseInfo$
  32.  */
  33. #include "linden_common.h"
  34. #include "../lldir.h"
  35. #include "../test/lltut.h"
  36. namespace tut
  37. {
  38. struct LLDirTest
  39.         {
  40.         };
  41.         typedef test_group<LLDirTest> LLDirTest_t;
  42.         typedef LLDirTest_t::object LLDirTest_object_t;
  43.         tut::LLDirTest_t tut_LLDirTest("LLDir");
  44. template<> template<>
  45. void LLDirTest_object_t::test<1>()
  46. // getDirDelimiter
  47. {
  48. ensure("getDirDelimiter", !gDirUtilp->getDirDelimiter().empty());
  49. }
  50. template<> template<>
  51. void LLDirTest_object_t::test<2>()
  52. // getBaseFileName
  53. {
  54. std::string delim = gDirUtilp->getDirDelimiter();
  55. std::string rawFile = "foo";
  56. std::string rawFileExt = "foo.bAr";
  57. std::string rawFileNullExt = "foo.";
  58. std::string rawExt = ".bAr";
  59. std::string rawDot = ".";
  60. std::string pathNoExt = "aa" + delim + "bb" + delim + "cc" + delim + "dd" + delim + "ee";
  61. std::string pathExt = pathNoExt + ".eXt";
  62. std::string dottedPathNoExt = "aa" + delim + "bb" + delim + "cc.dd" + delim + "ee";
  63. std::string dottedPathExt = dottedPathNoExt + ".eXt";
  64. // foo[.bAr]
  65. ensure_equals("getBaseFileName/r-no-ext/no-strip-exten",
  66.       gDirUtilp->getBaseFileName(rawFile, false),
  67.       "foo");
  68. ensure_equals("getBaseFileName/r-no-ext/strip-exten",
  69.       gDirUtilp->getBaseFileName(rawFile, true),
  70.       "foo");
  71. ensure_equals("getBaseFileName/r-ext/no-strip-exten",
  72.       gDirUtilp->getBaseFileName(rawFileExt, false),
  73.       "foo.bAr");
  74. ensure_equals("getBaseFileName/r-ext/strip-exten",
  75.       gDirUtilp->getBaseFileName(rawFileExt, true),
  76.       "foo");
  77. // foo.
  78. ensure_equals("getBaseFileName/rn-no-ext/no-strip-exten",
  79.       gDirUtilp->getBaseFileName(rawFileNullExt, false),
  80.       "foo.");
  81. ensure_equals("getBaseFileName/rn-no-ext/strip-exten",
  82.       gDirUtilp->getBaseFileName(rawFileNullExt, true),
  83.       "foo");
  84. // .bAr
  85. // interesting case - with no basename, this IS the basename, not the extension.
  86. ensure_equals("getBaseFileName/e-ext/no-strip-exten",
  87.       gDirUtilp->getBaseFileName(rawExt, false),
  88.       ".bAr");
  89. ensure_equals("getBaseFileName/e-ext/strip-exten",
  90.       gDirUtilp->getBaseFileName(rawExt, true),
  91.       ".bAr");
  92. // .
  93. ensure_equals("getBaseFileName/d/no-strip-exten",
  94.       gDirUtilp->getBaseFileName(rawDot, false),
  95.       ".");
  96. ensure_equals("getBaseFileName/d/strip-exten",
  97.       gDirUtilp->getBaseFileName(rawDot, true),
  98.       ".");
  99. // aa/bb/cc/dd/ee[.eXt]
  100. ensure_equals("getBaseFileName/no-ext/no-strip-exten",
  101.       gDirUtilp->getBaseFileName(pathNoExt, false),
  102.       "ee");
  103. ensure_equals("getBaseFileName/no-ext/strip-exten",
  104.       gDirUtilp->getBaseFileName(pathNoExt, true),
  105.       "ee");
  106. ensure_equals("getBaseFileName/ext/no-strip-exten",
  107.       gDirUtilp->getBaseFileName(pathExt, false),
  108.       "ee.eXt");
  109. ensure_equals("getBaseFileName/ext/strip-exten",
  110.       gDirUtilp->getBaseFileName(pathExt, true),
  111.       "ee");
  112. // aa/bb/cc.dd/ee[.eXt]
  113. ensure_equals("getBaseFileName/d-no-ext/no-strip-exten",
  114.       gDirUtilp->getBaseFileName(dottedPathNoExt, false),
  115.       "ee");
  116. ensure_equals("getBaseFileName/d-no-ext/strip-exten",
  117.       gDirUtilp->getBaseFileName(dottedPathNoExt, true),
  118.       "ee");
  119. ensure_equals("getBaseFileName/d-ext/no-strip-exten",
  120.       gDirUtilp->getBaseFileName(dottedPathExt, false),
  121.       "ee.eXt");
  122. ensure_equals("getBaseFileName/d-ext/strip-exten",
  123.       gDirUtilp->getBaseFileName(dottedPathExt, true),
  124.       "ee");
  125. }
  126. template<> template<>
  127. void LLDirTest_object_t::test<3>()
  128. // getDirName
  129. {
  130. std::string delim = gDirUtilp->getDirDelimiter();
  131. std::string rawFile = "foo";
  132. std::string rawFileExt = "foo.bAr";
  133. std::string pathNoExt = "aa" + delim + "bb" + delim + "cc" + delim + "dd" + delim + "ee";
  134. std::string pathExt = pathNoExt + ".eXt";
  135. std::string dottedPathNoExt = "aa" + delim + "bb" + delim + "cc.dd" + delim + "ee";
  136. std::string dottedPathExt = dottedPathNoExt + ".eXt";
  137. // foo[.bAr]
  138. ensure_equals("getDirName/r-no-ext",
  139.       gDirUtilp->getDirName(rawFile),
  140.       "");
  141. ensure_equals("getDirName/r-ext",
  142.       gDirUtilp->getDirName(rawFileExt),
  143.       "");
  144. // aa/bb/cc/dd/ee[.eXt]
  145. ensure_equals("getDirName/no-ext",
  146.       gDirUtilp->getDirName(pathNoExt),
  147.       "aa" + delim + "bb" + delim + "cc" + delim + "dd");
  148. ensure_equals("getDirName/ext",
  149.       gDirUtilp->getDirName(pathExt),
  150.       "aa" + delim + "bb" + delim + "cc" + delim + "dd");
  151. // aa/bb/cc.dd/ee[.eXt]
  152. ensure_equals("getDirName/d-no-ext",
  153.       gDirUtilp->getDirName(dottedPathNoExt),
  154.       "aa" + delim + "bb" + delim + "cc.dd");
  155. ensure_equals("getDirName/d-ext",
  156.       gDirUtilp->getDirName(dottedPathExt),
  157.       "aa" + delim + "bb" + delim + "cc.dd");
  158. }
  159. template<> template<>
  160. void LLDirTest_object_t::test<4>()
  161. // getExtension
  162. {
  163. std::string delim = gDirUtilp->getDirDelimiter();
  164. std::string rawFile = "foo";
  165. std::string rawFileExt = "foo.bAr";
  166. std::string rawFileNullExt = "foo.";
  167. std::string rawExt = ".bAr";
  168. std::string rawDot = ".";
  169. std::string pathNoExt = "aa" + delim + "bb" + delim + "cc" + delim + "dd" + delim + "ee";
  170. std::string pathExt = pathNoExt + ".eXt";
  171. std::string dottedPathNoExt = "aa" + delim + "bb" + delim + "cc.dd" + delim + "ee";
  172. std::string dottedPathExt = dottedPathNoExt + ".eXt";
  173. // foo[.bAr]
  174. ensure_equals("getExtension/r-no-ext",
  175.       gDirUtilp->getExtension(rawFile),
  176.       "");
  177. ensure_equals("getExtension/r-ext",
  178.       gDirUtilp->getExtension(rawFileExt),
  179.       "bar");
  180. // foo.
  181. ensure_equals("getExtension/rn-no-ext",
  182.       gDirUtilp->getExtension(rawFileNullExt),
  183.       "");
  184. // .bAr
  185. // interesting case - with no basename, this IS the basename, not the extension.
  186. ensure_equals("getExtension/e-ext",
  187.       gDirUtilp->getExtension(rawExt),
  188.       "");
  189. // .
  190. ensure_equals("getExtension/d",
  191.       gDirUtilp->getExtension(rawDot),
  192.       "");
  193. // aa/bb/cc/dd/ee[.eXt]
  194. ensure_equals("getExtension/no-ext",
  195.       gDirUtilp->getExtension(pathNoExt),
  196.       "");
  197. ensure_equals("getExtension/ext",
  198.       gDirUtilp->getExtension(pathExt),
  199.       "ext");
  200. // aa/bb/cc.dd/ee[.eXt]
  201. ensure_equals("getExtension/d-no-ext",
  202.       gDirUtilp->getExtension(dottedPathNoExt),
  203.       "");
  204. ensure_equals("getExtension/d-ext",
  205.       gDirUtilp->getExtension(dottedPathExt),
  206.       "ext");
  207. }
  208. }