session_options_unittest.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/base/session_options.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace remoting {
  7. TEST(SessionOptionsTest, ShouldBeAbleToAppendOptions) {
  8. SessionOptions options;
  9. options.Import("A:, B C :1, DE:2, EF");
  10. ASSERT_TRUE(options.Get("A"));
  11. ASSERT_EQ(*options.Get("B C "), "1");
  12. ASSERT_EQ(*options.Get("DE"), "2");
  13. ASSERT_FALSE(options.Get("EF"));
  14. ASSERT_FALSE(options.Get(" EF"));
  15. ASSERT_FALSE(options.Get("--FF"));
  16. options.Append("A", "100");
  17. options.Append("--FF", "3");
  18. ASSERT_EQ(*options.Get("A"), "100");
  19. ASSERT_EQ(*options.Get("--FF"), "3");
  20. }
  21. TEST(SessionOptionsTest, ShouldRemoveEmptyKeys) {
  22. SessionOptions options;
  23. options.Import("A:1,:,B:");
  24. ASSERT_TRUE(options.Get("A"));
  25. ASSERT_TRUE(options.Get("B"));
  26. ASSERT_FALSE(options.Get(""));
  27. }
  28. TEST(SessionOptionsTest, ShouldRemoveNonASCIIKeyOrValue) {
  29. SessionOptions options;
  30. options.Import("\xE9\x9B\xAA:value,key:\xE9\xA3\x9E,key2:value2");
  31. ASSERT_FALSE(options.Get("\xE9\x9B\xAA"));
  32. ASSERT_FALSE(options.Get("key"));
  33. ASSERT_EQ(*options.Get("key2"), "value2");
  34. }
  35. TEST(SessionOptionsTest, ImportAndExport) {
  36. SessionOptions options;
  37. options.Import("A:,B:,C:D,E:V");
  38. std::string result = options.Export();
  39. SessionOptions other;
  40. other.Append("C", "X");
  41. other.Import(result);
  42. ASSERT_EQ(options.Export(), other.Export());
  43. }
  44. TEST(SessionOptionsTest, ConvertToBool) {
  45. SessionOptions options;
  46. options.Import("A:,B:x,C:true,D:TRUE,E:1,F:2,G:FALSE,H:0,I");
  47. ASSERT_TRUE(*options.GetBool("A"));
  48. ASSERT_FALSE(options.GetBool("B"));
  49. ASSERT_TRUE(*options.GetBool("C"));
  50. ASSERT_TRUE(*options.GetBool("D"));
  51. ASSERT_TRUE(*options.GetBool("E"));
  52. ASSERT_FALSE(options.GetBool("F"));
  53. ASSERT_FALSE(*options.GetBool("G"));
  54. ASSERT_FALSE(*options.GetBool("H"));
  55. ASSERT_FALSE(options.GetBool("I"));
  56. }
  57. TEST(SessionOptionsTest, ConvertToint) {
  58. SessionOptions options;
  59. options.Import("A:100,B:-200,C:x,D:");
  60. ASSERT_EQ(*options.GetInt("A"), 100);
  61. ASSERT_EQ(*options.GetInt("B"), -200);
  62. ASSERT_FALSE(options.GetInt("C"));
  63. ASSERT_FALSE(options.GetInt("D"));
  64. }
  65. } // namespace remoting