PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/test/common/types/string_validation.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 56 lines | 25 code | 10 blank | 21 comment | 0 complexity | e256dad0b6ffba2c622c612296180516 MD5 | raw file
  1. /*
  2. * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file test/common/types/string_validation.cpp
  18. * @author Oskar Świtalski <o.switalski@samsung.com>
  19. * @version 1.0
  20. * @brief Tests for string validation functions
  21. */
  22. #include <cstring>
  23. #include <gtest/gtest.h>
  24. #include <common/types/string_validation.h>
  25. #include <cynara-limits.h>
  26. TEST(StringValidation, nullptrString) {
  27. EXPECT_FALSE(isStringValid(nullptr));
  28. EXPECT_TRUE(isExtraStringValid(nullptr));
  29. }
  30. TEST(StringValidation, emptyString) {
  31. const char *emptyString = "";
  32. EXPECT_TRUE(isStringValid(emptyString));
  33. EXPECT_TRUE(isExtraStringValid(emptyString));
  34. }
  35. TEST(StringValidation, maxString) {
  36. char maxString[CYNARA_MAX_ID_LENGTH + 1] = {0};
  37. memset(maxString,' ', CYNARA_MAX_ID_LENGTH);
  38. EXPECT_TRUE(isStringValid(maxString));
  39. EXPECT_TRUE(isExtraStringValid(maxString));
  40. }
  41. TEST(StringValidation, overMaxString) {
  42. char maxString[CYNARA_MAX_ID_LENGTH + 2] = {0};
  43. memset(maxString,' ', CYNARA_MAX_ID_LENGTH + 1);
  44. EXPECT_FALSE(isStringValid(maxString));
  45. EXPECT_FALSE(isExtraStringValid(maxString));
  46. }