1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Firestore/core/src/firebase/firestore/model/precondition.h"
#include "Firestore/core/src/firebase/firestore/model/document.h"
#include "Firestore/core/src/firebase/firestore/model/no_document.h"
#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
#include "gtest/gtest.h"
namespace firebase {
namespace firestore {
namespace model {
TEST(Precondition, None) {
const Precondition none = Precondition::None();
EXPECT_EQ(Precondition::Type::None, none.type());
EXPECT_TRUE(none.IsNone());
EXPECT_EQ(SnapshotVersion::None(), none.update_time());
const NoDocument deleted_doc = testutil::DeletedDoc("foo/doc", 1234567);
const Document doc = testutil::Doc("bar/doc", 7654321);
EXPECT_TRUE(none.IsValidFor(deleted_doc));
EXPECT_TRUE(none.IsValidFor(doc));
}
TEST(Precondition, Exists) {
const Precondition exists = Precondition::Exists(true);
const Precondition no_exists = Precondition::Exists(false);
EXPECT_EQ(Precondition::Type::Exists, exists.type());
EXPECT_EQ(Precondition::Type::Exists, no_exists.type());
EXPECT_FALSE(exists.IsNone());
EXPECT_FALSE(no_exists.IsNone());
EXPECT_EQ(SnapshotVersion::None(), exists.update_time());
EXPECT_EQ(SnapshotVersion::None(), no_exists.update_time());
const NoDocument deleted_doc = testutil::DeletedDoc("foo/doc", 1234567);
const Document doc = testutil::Doc("bar/doc", 7654321);
EXPECT_FALSE(exists.IsValidFor(deleted_doc));
EXPECT_TRUE(exists.IsValidFor(doc));
EXPECT_TRUE(no_exists.IsValidFor(deleted_doc));
EXPECT_FALSE(no_exists.IsValidFor(doc));
}
TEST(Precondition, UpdateTime) {
const Precondition update_time =
Precondition::UpdateTime(testutil::Version(1234567));
EXPECT_EQ(Precondition::Type::UpdateTime, update_time.type());
EXPECT_FALSE(update_time.IsNone());
EXPECT_EQ(testutil::Version(1234567), update_time.update_time());
const NoDocument deleted_doc = testutil::DeletedDoc("foo/doc", 1234567);
const Document not_match = testutil::Doc("bar/doc", 7654321);
const Document match = testutil::Doc("baz/doc", 1234567);
EXPECT_FALSE(update_time.IsValidFor(deleted_doc));
EXPECT_FALSE(update_time.IsValidFor(not_match));
EXPECT_TRUE(update_time.IsValidFor(match));
}
} // namespace model
} // namespace firestore
} // namespace firebase
|