transform_operations_test.mm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2018 Google
  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. #include "Firestore/core/src/firebase/firestore/model/transform_operations.h"
  17. #include "Firestore/core/src/firebase/firestore/model/field_value.h"
  18. #include "gtest/gtest.h"
  19. namespace firebase {
  20. namespace firestore {
  21. namespace model {
  22. class DummyOperation : public TransformOperation {
  23. public:
  24. DummyOperation() {
  25. }
  26. Type type() const override {
  27. return Type::Test;
  28. }
  29. FieldValue ApplyToLocalView(const absl::optional<model::FieldValue>& /* previous_value */,
  30. const Timestamp& /* local_write_time */) const override {
  31. return FieldValue::Null();
  32. }
  33. FieldValue ApplyToRemoteDocument(const absl::optional<model::FieldValue>& /* previous_value */,
  34. const FieldValue& /* transform_result */) const override {
  35. return FieldValue::Null();
  36. }
  37. bool idempotent() const override {
  38. return true;
  39. }
  40. bool operator==(const TransformOperation& other) const override {
  41. return this == &other;
  42. }
  43. NSUInteger Hash() const override {
  44. // arbitrary number, the same as used in ObjC implementation, since all
  45. // instances are equal.
  46. return 37;
  47. }
  48. };
  49. TEST(TransformOperations, ServerTimestamp) {
  50. ServerTimestampTransform transform = ServerTimestampTransform::Get();
  51. EXPECT_EQ(TransformOperation::Type::ServerTimestamp, transform.type());
  52. ServerTimestampTransform another = ServerTimestampTransform::Get();
  53. DummyOperation dummy;
  54. EXPECT_EQ(transform, another);
  55. EXPECT_NE(transform, dummy);
  56. }
  57. // TODO(mikelehen): Add ArrayTransform test once it no longer depends on
  58. // FSTFieldValue and can be exposed to C++ code.
  59. } // namespace model
  60. } // namespace firestore
  61. } // namespace firebase