File: OCAFExport_test.cpp

package info (click to toggle)
oce 0.18.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 301,548 kB
  • sloc: cpp: 1,190,609; ansic: 67,225; sh: 11,630; tcl: 7,954; cs: 5,221; python: 2,867; java: 1,522; makefile: 342; xml: 292; perl: 37
file content (62 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download | duplicates (6)
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
54
55
56
57
58
59
60
61
62
#include <AppStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TDocStd_Application.hxx>
#include <OSD_File.hxx>
#include <OSD_Path.hxx>
#include <TCollection_ExtendedString.hxx>
#include <LDOM_OSStream.hxx>
#include <iostream>
#include <gtest/gtest.h>

TEST(OCAFExportTestSuite, testExportAscii)
{
    const char * filename = "ascii.cbf";
    Handle(TDocStd_Application) app = new AppStd_Application();
    Handle(TDocStd_Document) doc;
    app->NewDocument("BinOcaf", doc);
    app->SaveAs(doc, filename);
    app->Close(doc);

    OSD_Path path(filename);
    OSD_File file(path);
    ASSERT_TRUE(file.Exists());
    file.Remove();
    ASSERT_FALSE(file.Failed());
}

TEST(OCAFExportTestSuite, testExportNonAscii)
{
    // Use codepoints and not characters to avoid encoding problems
    TCollection_ExtendedString extName("XX.cbf");
    extName.SetValue(1, 0x439);
    extName.SetValue(2, 0x446);
    char* filename = new char[extName.LengthOfCString()+1];
    extName.ToUTF8CString(filename);

    Handle(TDocStd_Application) app = new AppStd_Application();
    Handle(TDocStd_Document) doc;
    app->NewDocument("BinOcaf", doc);
    app->SaveAs(doc, filename);
    app->Close(doc);

    OSD_Path path(filename);
    OSD_File file(path);
    ASSERT_TRUE(file.Exists());
    file.Remove();
    ASSERT_FALSE(file.Failed());
    delete[] filename;
}

TEST(OCAFExportTestSuite, testOverflow)
{
    // See https://github.com/tpaviot/oce/pull/441
    LDOM_OSStream oss(128);
    oss << "line 1" << std::endl;
    oss << "line 2" << std::endl;
    ASSERT_TRUE(strlen(oss.str()) == 14);
}

int main(int argc, char **argv){
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}