PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mongo/util/text_test.cpp

https://gitlab.com/0072016/0072016-ApplePayDevice-
C++ | 91 lines | 57 code | 7 blank | 27 comment | 3 complexity | bdfa6b87c422e81bff2e157cb457d8a2 MD5 | raw file
  1. /*
  2. * Copyright 2012 10gen Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * As a special exception, the copyright holders give permission to link the
  17. * code of portions of this program with the OpenSSL library under certain
  18. * conditions as described in each individual source file and distribute
  19. * linked combinations including the program with the OpenSSL library. You
  20. * must comply with the GNU Affero General Public License in all respects
  21. * for all of the code used other than as permitted herein. If you modify
  22. * file(s) with this exception, you may extend this exception to your
  23. * version of the file(s), but you are not obligated to do so. If you do not
  24. * wish to do so, delete this exception statement from your version. If you
  25. * delete this exception statement from all source files in the program,
  26. * then also delete it in the license file.
  27. */
  28. #include <cstdarg>
  29. #include <string>
  30. #include <vector>
  31. #include "mongo/unittest/unittest.h"
  32. #include "mongo/util/text.h"
  33. using namespace mongo;
  34. static std::vector<std::string> svec(const char* first, ...) {
  35. std::vector<std::string> result;
  36. if (first) {
  37. result.push_back(first);
  38. va_list ap;
  39. va_start(ap, first);
  40. const char* curr;
  41. while (NULL != (curr = va_arg(ap, const char*))) {
  42. result.push_back(curr);
  43. }
  44. va_end(ap);
  45. }
  46. return result;
  47. }
  48. TEST(WindowsCommandLineConstruction, EmptyCommandLine) {
  49. ASSERT_EQUALS("", constructUtf8WindowsCommandLine(svec(NULL)));
  50. }
  51. TEST(WindowsCommandLineConstruction, NothingToQuote) {
  52. ASSERT_EQUALS("abc d \"\" e", constructUtf8WindowsCommandLine(svec("abc", "d", "", "e", NULL)));
  53. }
  54. TEST(WindowsCommandLineConstruction, ThingsToQuote) {
  55. ASSERT_EQUALS("a\\\\\\b \"de fg\" h",
  56. constructUtf8WindowsCommandLine(svec("a\\\\\\b", "de fg", "h", NULL)));
  57. ASSERT_EQUALS("\"a\\\\b c\" d e",
  58. constructUtf8WindowsCommandLine(svec("a\\\\b c", "d", "e", NULL)));
  59. ASSERT_EQUALS("\"a \\\\\" \\", constructUtf8WindowsCommandLine(svec("a \\", "\\", NULL)));
  60. ASSERT_EQUALS("\"\\\\\\\\\\\"\"", constructUtf8WindowsCommandLine(svec("\\\\\"", NULL)));
  61. }
  62. TEST(WindowsCommandLineConstruction, RegressionSERVER_7252) {
  63. ASSERT_EQUALS(
  64. "mongod \"--serviceName=My Service\" --serviceDescription \"My Service\" "
  65. "--serviceDisplayName \"My Service\" --dbpath C:\\mongo\\data\\config "
  66. "--port 20001 --logpath C:\\mongo\\logs\\mongo_config.log.txt "
  67. "--configsvr --service",
  68. constructUtf8WindowsCommandLine(svec("mongod",
  69. "--serviceName=My Service",
  70. "--serviceDescription",
  71. "My Service",
  72. "--serviceDisplayName",
  73. "My Service",
  74. "--dbpath",
  75. "C:\\mongo\\data\\config",
  76. "--port",
  77. "20001",
  78. "--logpath",
  79. "C:\\mongo\\logs\\mongo_config.log.txt",
  80. "--configsvr",
  81. "--service",
  82. NULL)));
  83. }