transform_operations_test.mm 2.1 KB

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