mirror of
https://github.com/fumiama/base16384.git
synced 2026-06-06 10:40:30 +08:00
fix(file): wierd fgetc/ungetc behavior on Windows
This commit is contained in:
@@ -97,14 +97,14 @@ static char tstbuf[BASE16384_ENCBUFSZ];
|
||||
for(i = TEST_SIZE; i > 0; i--) { \
|
||||
reset_and_truncate(fd, i); \
|
||||
\
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND); \
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND, 0644); \
|
||||
loop_ok(!fdout, i, "open"); \
|
||||
\
|
||||
err = base16384_encode_fd_detailed(fd, fdout, encbuf, decbuf, flag); \
|
||||
base16384_loop_ok(err); \
|
||||
loop_ok(close(fd), i, "close"); \
|
||||
\
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT); \
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
|
||||
loop_ok(!fdval, i, "open"); \
|
||||
\
|
||||
loop_ok(lseek(fdout, 0, SEEK_SET), i, "lseek"); \
|
||||
@@ -124,7 +124,7 @@ static char tstbuf[BASE16384_ENCBUFSZ];
|
||||
for(i = TEST_SIZE; i > 0; i--) { \
|
||||
reset_and_truncate(fd, i); \
|
||||
\
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND); \
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND, 0644); \
|
||||
loop_ok(!fdout, i, "open"); \
|
||||
\
|
||||
err = base16384_encode_stream_detailed(&(base16384_stream_t){ \
|
||||
@@ -137,7 +137,7 @@ static char tstbuf[BASE16384_ENCBUFSZ];
|
||||
base16384_loop_ok(err); \
|
||||
loop_ok(close(fd), i, "close"); \
|
||||
\
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT); \
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
|
||||
loop_ok(!fdval, i, "open"); \
|
||||
\
|
||||
loop_ok(lseek(fdout, 0, SEEK_SET), i, "lseek"); \
|
||||
@@ -171,12 +171,6 @@ static char tstbuf[BASE16384_ENCBUFSZ];
|
||||
\
|
||||
test_##name##_detailed(BASE16384_FLAG_NOHEADER|BASE16384_FLAG_SUM_CHECK_ON_REMAIN|BASE16384_FLAG_DO_SUM_CHECK_FORCELY);
|
||||
|
||||
|
||||
#define remove_test_files() \
|
||||
remove(TEST_INPUT_FILENAME); \
|
||||
remove(TEST_OUTPUT_FILENAME); \
|
||||
remove(TEST_VALIDATE_FILENAME);
|
||||
|
||||
int main() {
|
||||
srand(time(NULL));
|
||||
|
||||
@@ -184,6 +178,8 @@ int main() {
|
||||
int fd, i;
|
||||
base16384_err_t err;
|
||||
|
||||
init_test_files();
|
||||
|
||||
test_detailed(file);
|
||||
test_detailed(fp);
|
||||
test_detailed(fd);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ok(has_failed, reason) \
|
||||
if (has_failed) { \
|
||||
perror(reason); \
|
||||
@@ -83,8 +85,9 @@
|
||||
}
|
||||
|
||||
#define init_input_file() \
|
||||
for(i = 0; i < BASE16384_ENCBUFSZ; i += sizeof(int)) { \
|
||||
*(int*)(&encbuf[i]) = rand(); \
|
||||
fprintf(stderr, "fill encbufsz: %d\n", BASE16384_ENCBUFSZ);\
|
||||
for(i = 0; i < BASE16384_ENCBUFSZ/sizeof(uint16_t); i++) { \
|
||||
((uint16_t*)encbuf)[i] = (uint16_t)rand(); \
|
||||
} \
|
||||
fp = fopen(TEST_INPUT_FILENAME, "wb"); \
|
||||
ok(!fp, "fopen"); \
|
||||
@@ -92,6 +95,23 @@
|
||||
ok(fclose(fp), "fclose"); \
|
||||
fputs("input file created.\n", stderr);
|
||||
|
||||
#define init_test_files() {\
|
||||
fd = open(TEST_INPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT, 0644); \
|
||||
ok(fd<0, "open"); \
|
||||
ok(close(fd), "close"); \
|
||||
fd = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT, 0644); \
|
||||
ok(fd<0, "open"); \
|
||||
ok(close(fd), "close"); \
|
||||
fd = open(TEST_VALIDATE_FILENAME, O_RDWR|O_TRUNC|O_CREAT, 0644); \
|
||||
ok(fd<0, "open"); \
|
||||
ok(close(fd), "close");
|
||||
|
||||
#define remove_test_files() \
|
||||
remove(TEST_INPUT_FILENAME); \
|
||||
remove(TEST_OUTPUT_FILENAME); \
|
||||
remove(TEST_VALIDATE_FILENAME); \
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -50,6 +50,8 @@ int main() {
|
||||
int fd, i;
|
||||
base16384_err_t err;
|
||||
|
||||
init_test_files();
|
||||
|
||||
fputs("testing base16384_en/decode_file...\n", stderr);
|
||||
init_input_file();
|
||||
for(i = TEST_SIZE; i > 0; i--) {
|
||||
@@ -101,14 +103,14 @@ int main() {
|
||||
for(i = TEST_SIZE; i > 0; i--) {
|
||||
reset_and_truncate(fd, i);
|
||||
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND);
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND, 0644);
|
||||
loop_ok(!fdout, i, "open");
|
||||
|
||||
err = base16384_encode_fd(fd, fdout, encbuf, decbuf);
|
||||
base16384_loop_ok(err);
|
||||
loop_ok(close(fd), i, "close");
|
||||
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT);
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT, 0644);
|
||||
loop_ok(!fdval, i, "open");
|
||||
|
||||
loop_ok(lseek(fdout, 0, SEEK_SET), i, "lseek");
|
||||
@@ -127,7 +129,7 @@ int main() {
|
||||
for(i = TEST_SIZE; i > 0; i--) {
|
||||
reset_and_truncate(fd, i);
|
||||
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND);
|
||||
int fdout = open(TEST_OUTPUT_FILENAME, O_RDWR|O_TRUNC|O_CREAT|O_APPEND, 0644);
|
||||
loop_ok(!fdout, i, "open");
|
||||
|
||||
err = base16384_encode_stream(&(base16384_stream_t){
|
||||
@@ -140,7 +142,7 @@ int main() {
|
||||
base16384_loop_ok(err);
|
||||
loop_ok(close(fd), i, "close");
|
||||
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT);
|
||||
int fdval = open(TEST_VALIDATE_FILENAME, O_WRONLY|O_TRUNC|O_CREAT, 0644);
|
||||
loop_ok(!fdval, i, "open");
|
||||
|
||||
loop_ok(lseek(fdout, 0, SEEK_SET), i, "lseek");
|
||||
@@ -160,9 +162,7 @@ int main() {
|
||||
validate_result();
|
||||
}
|
||||
|
||||
remove(TEST_INPUT_FILENAME);
|
||||
remove(TEST_OUTPUT_FILENAME);
|
||||
remove(TEST_VALIDATE_FILENAME);
|
||||
remove_test_files();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user