File: Bug_3532_Regression_Test.cpp

package info (click to toggle)
ace 8.0.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,088 kB
  • sloc: cpp: 342,864; perl: 31,902; sh: 1,963; python: 532; yacc: 524; xml: 330; lex: 158; lisp: 116; makefile: 85; csh: 20; ansic: 19; tcl: 5
file content (53 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 * @file Bug_3532_Regression_Test.cpp
 *
 * Reproduces the problems reported in bug 3532
 *   http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3532
 *
 * @author Martin Gaus <Gaus at gmx dot de>
 */

#include "test_config.h"
#include "ace/ACE.h"

int
run_main (int, ACE_TCHAR *[])
{
    ACE_START_TEST (ACE_TEXT ("Bug_3532_Regression_Test"));

    char Buffer[10];
    int result = 0;

    // Write a ASCII file with one byte (no BOM)
    Buffer[0] = 'T';
    FILE* pFile = ACE_OS::fopen(ACE_TEXT("OneByteFile"), ACE_TEXT("wb"));
    ACE_OS::fwrite(&Buffer, 1, 1, pFile);
    ACE_OS::fclose(pFile);

    // Reopen the file and read the byte
    Buffer[0] = '-';
    pFile = ACE_OS::fopen(ACE_TEXT("OneByteFile"), ACE_TEXT("rb"));
    size_t BytesRead = ACE_OS::fread(&Buffer, 1, 1, pFile);
    if(BytesRead == 1)
    {
        if(Buffer[0] != 'T')
        {
            ++result;
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("Error: 'T' expected!!!\n")));
        }
    }
    else
    {
        ++result;
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Error: One byte should be read!!!\n")));
    }

    ACE_OS::fclose(pFile);

    ACE_END_TEST;

    return result;
}