transform_operations_test.mm 2.0 KB

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