is_equal_ut.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "is_equal.h"
  2. #include <library/cpp/protobuf/util/ut/sample_for_is_equal.pb.h>
  3. #include <library/cpp/testing/unittest/registar.h>
  4. #include <google/protobuf/descriptor.h>
  5. Y_UNIT_TEST_SUITE(ProtobufIsEqual) {
  6. const ::google::protobuf::Descriptor* Descr = TSampleForIsEqual::descriptor();
  7. const ::google::protobuf::FieldDescriptor* NameDescr = Descr->field(0);
  8. const ::google::protobuf::FieldDescriptor* InnerDescr = Descr->field(1);
  9. Y_UNIT_TEST(CheckDescriptors) {
  10. UNIT_ASSERT(Descr);
  11. UNIT_ASSERT(NameDescr);
  12. UNIT_ASSERT_VALUES_EQUAL(NameDescr->name(), "Name");
  13. UNIT_ASSERT_VALUES_EQUAL(InnerDescr->name(), "Inner");
  14. }
  15. Y_UNIT_TEST(IsEqual1) {
  16. TSampleForIsEqual a;
  17. TSampleForIsEqual b;
  18. a.SetName("aaa");
  19. b.SetName("bbb");
  20. TString path;
  21. bool equal = NProtoBuf::IsEqual(a, b, &path);
  22. UNIT_ASSERT(!equal);
  23. UNIT_ASSERT_VALUES_EQUAL("Name", path);
  24. UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr));
  25. }
  26. Y_UNIT_TEST(IsEqual2) {
  27. TSampleForIsEqual a;
  28. TSampleForIsEqual b;
  29. a.MutableInner()->SetBrbrbr("aaa");
  30. b.MutableInner()->SetBrbrbr("bbb");
  31. TString path;
  32. bool equal = NProtoBuf::IsEqual(a, b, &path);
  33. UNIT_ASSERT(!equal);
  34. UNIT_ASSERT_VALUES_EQUAL("Inner/Brbrbr", path);
  35. bool equalField = NProtoBuf::IsEqualField(a, b, *InnerDescr);
  36. UNIT_ASSERT(!equalField);
  37. }
  38. Y_UNIT_TEST(IsEqual3) {
  39. TSampleForIsEqual a;
  40. TSampleForIsEqual b;
  41. a.SetName("aaa");
  42. a.MutableInner()->SetBrbrbr("bbb");
  43. b.SetName("aaa");
  44. b.MutableInner()->SetBrbrbr("bbb");
  45. TString path;
  46. UNIT_ASSERT(NProtoBuf::IsEqual(a, b));
  47. UNIT_ASSERT(NProtoBuf::IsEqualField(a, b, *NameDescr));
  48. UNIT_ASSERT(NProtoBuf::IsEqualField(a, b, *InnerDescr));
  49. b.MutableInner()->SetBrbrbr("ccc");
  50. UNIT_ASSERT(!NProtoBuf::IsEqual(a, b));
  51. UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *InnerDescr));
  52. b.SetName("ccc");
  53. UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr));
  54. }
  55. Y_UNIT_TEST(IsEqualDefault) {
  56. TSampleForIsEqual a;
  57. TSampleForIsEqual b;
  58. a.SetName("");
  59. UNIT_ASSERT(NProtoBuf::IsEqualDefault(a, b));
  60. UNIT_ASSERT(!NProtoBuf::IsEqual(a, b));
  61. UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr));
  62. UNIT_ASSERT(NProtoBuf::IsEqualFieldDefault(a, b, *NameDescr));
  63. }
  64. }