stat_test.cc
Go to the documentation of this file.
1 //
2 // Copyright 2020 gRPC authors.
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 
18 
19 #include <stdio.h>
20 #include <string.h>
21 
22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
24 
25 #include <grpc/grpc.h>
26 #include <grpc/slice.h>
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/log.h>
29 
34 
35 namespace grpc_core {
36 namespace testing {
37 namespace {
38 
39 TEST(STAT, GetTimestampOnTmpFile) {
40  // Create a temporary empty file.
41  FILE* tmp = nullptr;
42  char* tmp_name;
43  tmp = gpr_tmpfile("prefix", &tmp_name);
44  ASSERT_NE(tmp_name, nullptr);
45  ASSERT_NE(tmp, nullptr);
46  fclose(tmp);
47  // Check the last modified date is correctly set.
48  time_t timestamp = 0;
49  absl::Status status = GetFileModificationTime(tmp_name, &timestamp);
51  EXPECT_GT(timestamp, 0);
52  // Clean up.
53  remove(tmp_name);
54  gpr_free(tmp_name);
55 }
56 
57 TEST(STAT, GetTimestampOnFailure) {
58  time_t timestamp = 0;
59  absl::Status status = GetFileModificationTime("/DOES_NOT_EXIST", &timestamp);
61  // Check the last modified date is not set.
62  EXPECT_EQ(timestamp, 0);
63 }
64 
65 } // namespace
66 } // namespace testing
67 } // namespace grpc_core
68 
69 int main(int argc, char** argv) {
71  ::testing::InitGoogleTest(&argc, argv);
72  return RUN_ALL_TESTS();
73 }
testing
Definition: aws_request_signer_test.cc:25
ASSERT_NE
#define ASSERT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2060
log.h
generate.env
env
Definition: generate.py:37
load_file.h
slice.h
grpc_core
Definition: call_metric_recorder.h:31
string.h
EXPECT_GT
#define EXPECT_GT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2036
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
gpr_tmpfile
FILE * gpr_tmpfile(const char *prefix, char **tmp_filename)
status
absl::Status status
Definition: rls.cc:251
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
absl::StatusCode::kInternal
@ kInternal
grpc_core::GetFileModificationTime
absl::Status GetFileModificationTime(const char *filename, time_t *timestamp)
grpc.h
tmpfile.h
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
stat.h
main
int main(int argc, char **argv)
Definition: stat_test.cc:69
test_config.h
absl::StatusCode::kOk
@ kOk
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
benchmark.FILE
FILE
Definition: benchmark.py:21
grpc::fclose
fclose(creds_file)
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
alloc.h
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_core::testing::TEST
TEST(ServiceConfigParserTest, DoubleRegistration)
Definition: service_config_test.cc:448
autogen_x86imm.tmp
tmp
Definition: autogen_x86imm.py:12
absl::Status::code
absl::StatusCode code() const
Definition: third_party/abseil-cpp/absl/status/status.cc:233


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:17