sys_time_test.cpp revision 27586ebe1a7f2f45651b855a26b3203d63d015d6
1f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes/* 2f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * Copyright (C) 2013 The Android Open Source Project 3f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * 4f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * you may not use this file except in compliance with the License. 6f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * You may obtain a copy of the License at 7f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * 8f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * 10f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * Unless required by applicable law or agreed to in writing, software 11f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * See the License for the specific language governing permissions and 14f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes * limitations under the License. 15f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes */ 16f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes 17f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes#include <gtest/gtest.h> 18f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes 19f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes#include <errno.h> 20f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes#include <sys/time.h> 21f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes 2227586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes#include "TemporaryFile.h" 2327586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes 24f8fcfbc85a3ce3e195626b90736d3a484331494bElliott HughesTEST(sys_time, utimes) { 25f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes timeval tv[2]; 26f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes memset(&tv, 0, sizeof(tv)); 27f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes 28f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes tv[0].tv_usec = -123; 29f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(-1, utimes("/", tv)); 30f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(EINVAL, errno); 31f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes tv[0].tv_usec = 1234567; 32f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(-1, utimes("/", tv)); 33f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(EINVAL, errno); 34f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes tv[0].tv_usec = 0; 35f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes 36f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes tv[1].tv_usec = -123; 37f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(-1, utimes("/", tv)); 38f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(EINVAL, errno); 39f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes tv[1].tv_usec = 1234567; 40f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(-1, utimes("/", tv)); 41f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes ASSERT_EQ(EINVAL, errno); 42f8fcfbc85a3ce3e195626b90736d3a484331494bElliott Hughes} 4327586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes 4427586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes// http://b/11383777 4527586ebe1a7f2f45651b855a26b3203d63d015d6Elliott HughesTEST(sys_time, utimes_NULL) { 4627586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes TemporaryFile tf; 4727586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes ASSERT_EQ(0, utimes(tf.filename, NULL)); 4827586ebe1a7f2f45651b855a26b3203d63d015d6Elliott Hughes} 49