dwcaress / MB-System

MB-System is an open source software package for the processing and display of bathymetry and backscatter imagery data derived from multibeam, interferometry, and sidescan sonars.
https://www.mbari.org/products/research-software/mb-system/
Other
128 stars 45 forks source link

Testing for surf library's xdr encode/decode #914

Open schwehr opened 4 years ago

schwehr commented 4 years ago

Trying to sketch out how to do testing of xdr_surf.[ch]. Should be able to do it without having to touch files on disk... here is a sketch of how I think it should be done. I used xdr_int to stand in for calls from the API.

#include "xdr_surf.h"

#include <rpc/xdr.h>
#include <cstdint>
#include <cstdio>
#include <vector>

#include "testing/base/public/gunit.h"

namespace {

TEST(SurfTest, WriteRead) {
  std::vector<char> buf(8, 0);
  int expected = -123;
  {
    FILE *out = fmemopen(buf.data(), 8, "w");
    XDR xdrs;
    xdrstdio_create(&xdrs, out, XDR_ENCODE);
    int value = expected;
    EXPECT_TRUE(xdr_int(&xdrs, &value));
    xdr_destroy(&xdrs);
    EXPECT_EQ(0, fclose(out));
  }

  {
    FILE *in = fmemopen(buf.data(), 8, "r");
    XDR xdrs;
    xdrstdio_create(&xdrs, in, XDR_DECODE);
    int value = 0;
    EXPECT_TRUE(xdr_int(&xdrs, &value));
    EXPECT_EQ(expected, value);
    xdr_destroy(&xdrs);
    EXPECT_EQ(0, fclose(in));
  }
}

}  // namespace
schwehr commented 4 years ago

Or probably xdrmem_create rather than fmemopen and xdrstdio_create

dwcaress commented 4 years ago

The formats that are based on XDR are Surf (181), the Atlas HSMD (101, 102) and HSDS2 (182, 183) formats, and all of the HMRG MR1 formats (61, 62, 63, 64).