transform_operations_test.mm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. absl::optional<model::FieldValue> ComputeBaseValue(
  38. const absl::optional<model::FieldValue>& previous_value) const override {
  39. return absl::nullopt;
  40. }
  41. bool operator==(const TransformOperation& other) const override {
  42. return this == &other;
  43. }
  44. NSUInteger Hash() const override {
  45. // arbitrary number, the same as used in ObjC implementation, since all
  46. // instances are equal.
  47. return 37;
  48. }
  49. };
  50. TEST(TransformOperations, ServerTimestamp) {
  51. ServerTimestampTransform transform = ServerTimestampTransform::Get();
  52. EXPECT_EQ(TransformOperation::Type::ServerTimestamp, transform.type());
  53. ServerTimestampTransform another = ServerTimestampTransform::Get();
  54. DummyOperation dummy;
  55. EXPECT_EQ(transform, another);
  56. EXPECT_NE(transform, dummy);
  57. }
  58. // TODO(mikelehen): Add ArrayTransform test once it no longer depends on
  59. // FSTFieldValue and can be exposed to C++ code.
  60. } // namespace model
  61. } // namespace firestore
  62. } // namespace firebase