Changeset 136 for trunk/samba/source/lib/replace/test
- Timestamp:
- May 29, 2008, 12:22:03 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/samba/source/lib/replace/test/testsuite.c
r133 r136 870 870 871 871 printf("success: getifaddrs\n"); 872 return true; 873 } 874 875 static int test_utime(void) 876 { 877 struct utimbuf u; 878 struct stat st1, st2, st3; 879 int fd; 880 881 printf("test: utime\n"); 882 unlink(TESTFILE); 883 884 fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); 885 if (fd == -1) { 886 printf("failure: utime [\n" 887 "creating '%s' failed - %s\n]\n", 888 TESTFILE, strerror(errno)); 889 return false; 890 } 891 892 if (fstat(fd, &st1) != 0) { 893 printf("failure: utime [\n" 894 "fstat (1) failed - %s\n]\n", 895 strerror(errno)); 896 return false; 897 } 898 899 u.actime = st1.st_atime + 300; 900 u.modtime = st1.st_mtime - 300; 901 if (utime(TESTFILE, &u) != 0) { 902 printf("failure: utime [\n" 903 "utime(&u) failed - %s\n]\n", 904 strerror(errno)); 905 return false; 906 } 907 908 if (fstat(fd, &st2) != 0) { 909 printf("failure: utime [\n" 910 "fstat (2) failed - %s\n]\n", 911 strerror(errno)); 912 return false; 913 } 914 915 if (utime(TESTFILE, NULL) != 0) { 916 printf("failure: utime [\n" 917 "utime(NULL) failed - %s\n]\n", 918 strerror(errno)); 919 return false; 920 } 921 922 if (fstat(fd, &st3) != 0) { 923 printf("failure: utime [\n" 924 "fstat (3) failed - %s\n]\n", 925 strerror(errno)); 926 return false; 927 } 928 929 #define CMP_VAL(a,c,b) do { \ 930 if (a c b) { \ 931 printf("failure: utime [\n" \ 932 "%s: %s(%d) %s %s(%d)\n]\n", \ 933 __location__, \ 934 #a, (int)a, #c, #b, (int)b); \ 935 return false; \ 936 } \ 937 } while(0) 938 #define EQUAL_VAL(a,b) CMP_VAL(a,!=,b) 939 #define GREATER_VAL(a,b) CMP_VAL(a,<=,b) 940 #define LESSER_VAL(a,b) CMP_VAL(a,>=,b) 941 942 EQUAL_VAL(st2.st_atime, st1.st_atime + 300); 943 EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300); 944 LESSER_VAL(st3.st_atime, st2.st_atime); 945 GREATER_VAL(st3.st_mtime, st2.st_mtime); 946 947 #undef CMP_VAL 948 #undef EQUAL_VAL 949 #undef GREATER_VAL 950 #undef LESSER_VAL 951 952 unlink(TESTFILE); 953 printf("success: utime\n"); 954 return true; 955 } 956 957 static int test_utimes(void) 958 { 959 struct timeval tv[2]; 960 struct stat st1, st2; 961 int fd; 962 963 printf("test: utimes\n"); 964 unlink(TESTFILE); 965 966 fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); 967 if (fd == -1) { 968 printf("failure: utimes [\n" 969 "creating '%s' failed - %s\n]\n", 970 TESTFILE, strerror(errno)); 971 return false; 972 } 973 974 if (fstat(fd, &st1) != 0) { 975 printf("failure: utimes [\n" 976 "fstat (1) failed - %s\n]\n", 977 strerror(errno)); 978 return false; 979 } 980 981 ZERO_STRUCT(tv); 982 tv[0].tv_sec = st1.st_atime + 300; 983 tv[1].tv_sec = st1.st_mtime - 300; 984 if (utimes(TESTFILE, tv) != 0) { 985 printf("failure: utimes [\n" 986 "utimes(tv) failed - %s\n]\n", 987 strerror(errno)); 988 return false; 989 } 990 991 if (fstat(fd, &st2) != 0) { 992 printf("failure: utimes [\n" 993 "fstat (2) failed - %s\n]\n", 994 strerror(errno)); 995 return false; 996 } 997 998 #define EQUAL_VAL(a,b) do { \ 999 if (a != b) { \ 1000 printf("failure: utimes [\n" \ 1001 "%s: %s(%d) != %s(%d)\n]\n", \ 1002 __location__, \ 1003 #a, (int)a, #b, (int)b); \ 1004 return false; \ 1005 } \ 1006 } while(0) 1007 1008 EQUAL_VAL(st2.st_atime, st1.st_atime + 300); 1009 EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300); 1010 1011 #undef EQUAL_VAL 1012 1013 unlink(TESTFILE); 1014 printf("success: utimes\n"); 872 1015 return true; 873 1016 } … … 921 1064 ret &= test_strptime(); 922 1065 ret &= test_getifaddrs(); 1066 ret &= test_utime(); 1067 ret &= test_utimes(); 923 1068 924 1069 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.