File: test_open_close.cpp

package info (click to toggle)
netcdf-cxx 4.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,456 kB
  • sloc: cpp: 8,506; sh: 4,548; ansic: 4,251; xml: 173; makefile: 145
file content (57 lines) | stat: -rw-r--r-- 1,405 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
54
55
56
57
/*! Test open() and close() methods for NcFile.
 *
 * Methods contributed by user `Luthaf`. See
 * https://github.com/Unidata/netcdf-cxx4/pull/18/files
 * for more information.
 */
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <netcdf>
#include <iomanip>
#include "test_utilities.h"
using namespace std;
using namespace netCDF;
using namespace netCDF::exceptions;

/*! Standard 'main' function.
 *
 */
int main() {
    NcFile file;

    // Test opening a null file. Should fail.
    cout << "Attempting to open a file that doesn't exist... ";
    try {
      file.open("Doesn't Exist.",NcFile::read);
      cout << "Error. Expected an exception." << endl;
      return -1;
    } catch(NcException &e) {
      cout << "Caught Expected Exception." << endl;
    }

    // Test opening a file that exists.
    cout << "Opening file \"firstFile.cdf\"... ";
    try {
      file.open("firstFile.cdf",NcFile::replace);
      cout << "Success." << endl;
    } catch(NcException &e) {
      cout << "Caught unexpected exception." << endl;
      return e.errorCode();
    }

    // Test closing a valid file.
    cout << "Closing file...";
    try {
      file.close();
      cout << "Success." << endl;
    } catch(NcException &e) {
      cout << "Caught unexpected exception." << endl;
      return e.errorCode();
    }


    cout << endl << "Finished." << endl;
    return 0;
}