blob: 31930836094a2b2b819ba6e1f3f8172824bf2a37 [file] [log] [blame]
Elliott Hughesa55f6302013-01-02 14:23:43 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
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
17#include <gtest/gtest.h>
Elliott Hughesb4f76162013-09-19 16:27:24 -070018#include "TemporaryFile.h"
Elliott Hughesa55f6302013-01-02 14:23:43 -080019
Elliott Hughes428f5562013-02-05 16:10:59 -080020#include <stdint.h>
Elliott Hughesa55f6302013-01-02 14:23:43 -080021#include <unistd.h>
22
23TEST(unistd, sysconf_SC_MONOTONIC_CLOCK) {
24 ASSERT_GT(sysconf(_SC_MONOTONIC_CLOCK), 0);
25}
Elliott Hughes428f5562013-02-05 16:10:59 -080026
27TEST(unistd, sbrk) {
28 void* initial_break = sbrk(0);
29
30 void* new_break = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(initial_break) + 2000);
31 ASSERT_EQ(0, brk(new_break));
32
33 void* final_break = sbrk(0);
34 ASSERT_EQ(final_break, new_break);
35}
Elliott Hughesb4f76162013-09-19 16:27:24 -070036
37TEST(unistd, truncate) {
38 TemporaryFile tf;
39 ASSERT_EQ(0, close(tf.fd));
40 ASSERT_EQ(0, truncate(tf.filename, 123));
41
42 struct stat sb;
43 ASSERT_EQ(0, stat(tf.filename, &sb));
44 ASSERT_EQ(123, sb.st_size);
45}
46
47TEST(unistd, truncate64) {
48 TemporaryFile tf;
49 ASSERT_EQ(0, close(tf.fd));
50 ASSERT_EQ(0, truncate64(tf.filename, 123));
51
52 struct stat sb;
53 ASSERT_EQ(0, stat(tf.filename, &sb));
54 ASSERT_EQ(123, sb.st_size);
55}
56
57TEST(unistd, ftruncate) {
58 TemporaryFile tf;
59 ASSERT_EQ(0, ftruncate(tf.fd, 123));
60 ASSERT_EQ(0, close(tf.fd));
61
62 struct stat sb;
63 ASSERT_EQ(0, stat(tf.filename, &sb));
64 ASSERT_EQ(123, sb.st_size);
65}
66
67TEST(unistd, ftruncate64) {
68 TemporaryFile tf;
69 ASSERT_EQ(0, ftruncate64(tf.fd, 123));
70 ASSERT_EQ(0, close(tf.fd));
71
72 struct stat sb;
73 ASSERT_EQ(0, stat(tf.filename, &sb));
74 ASSERT_EQ(123, sb.st_size);
75}