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

/test/common/exceptions/bucketrecordcorrupted.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 92 lines | 52 code | 19 blank | 21 comment | 0 complexity | 53a7e9cc96488d6c018db605ef9c55b4 MD5 | raw file
  1. /*
  2. * Copyright (c) 2014 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/exceptions/bucketrecordcorrupted.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Tests for Cynara::BucketRecordCorruptedException
  21. */
  22. #include <gtest/gtest.h>
  23. #include <gmock/gmock.h>
  24. #include "exceptions/BucketRecordCorruptedException.h"
  25. using namespace Cynara;
  26. TEST(BucketRecordCorruptedException, line) {
  27. using ::testing::StartsWith;
  28. BucketRecordCorruptedException ex("line");
  29. auto expected = "Bucket record corrupted at line: <line>";
  30. ASSERT_THAT(ex.what(), StartsWith(expected));
  31. ASSERT_EQ("line", ex.line());
  32. ASSERT_EQ("", ex.filename());
  33. ASSERT_EQ(static_cast<size_t>(0), ex.lineNumber());
  34. }
  35. TEST(BucketRecordCorruptedException, line_lineno) {
  36. using ::testing::StartsWith;
  37. auto ex = BucketRecordCorruptedException("line").withLineNumber(10);
  38. auto expected = "Bucket record corrupted at line 10: <line>";
  39. ASSERT_THAT(ex.what(), StartsWith(expected));
  40. ASSERT_EQ("line", ex.line());
  41. ASSERT_EQ("", ex.filename());
  42. ASSERT_EQ(static_cast<size_t>(10), ex.lineNumber());
  43. }
  44. TEST(BucketRecordCorruptedException, line_lineno_filename) {
  45. using ::testing::StartsWith;
  46. auto ex = BucketRecordCorruptedException("line").withLineNumber(10).withFilename("bucket.bkt");
  47. auto expected = "Bucket record corrupted at bucket.bkt:10: <line>";
  48. ASSERT_THAT(ex.what(), StartsWith(expected));
  49. ASSERT_EQ("line", ex.line());
  50. ASSERT_EQ("bucket.bkt", ex.filename());
  51. ASSERT_EQ(static_cast<size_t>(10), ex.lineNumber());
  52. }
  53. TEST(BucketRecordCorruptedException, line_filename) {
  54. using ::testing::StartsWith;
  55. auto ex = BucketRecordCorruptedException("line").withFilename("bucket.bkt");
  56. auto expected = "Bucket record corrupted at bucket.bkt: <line>";
  57. ASSERT_THAT(ex.what(), StartsWith(expected));
  58. ASSERT_EQ("line", ex.line());
  59. ASSERT_EQ("bucket.bkt", ex.filename());
  60. ASSERT_EQ(static_cast<size_t>(0), ex.lineNumber());
  61. }
  62. TEST(BucketRecordCorruptedException, line_sliced) {
  63. using ::testing::StartsWith;
  64. std::string line = "A very long line placed here just to check,"
  65. " if slicing works as expected (83 chars)";
  66. auto ex = BucketRecordCorruptedException(line);
  67. auto expected = "Bucket record corrupted at line:"
  68. " <A very long line placed here just to check, if sli...>";
  69. ASSERT_THAT(ex.what(), StartsWith(expected));
  70. ASSERT_EQ(line, ex.line());
  71. ASSERT_EQ("", ex.filename());
  72. ASSERT_EQ(static_cast<size_t>(0), ex.lineNumber());
  73. }