Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
schwehr opened this issue Feb 4, 2020 · 2 comments
Open

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

schwehr opened this issue Feb 4, 2020 · 2 comments

Comments

@schwehr
Copy link
Collaborator

schwehr commented Feb 4, 2020

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
Copy link
Collaborator Author

schwehr commented Feb 4, 2020

Or probably xdrmem_create rather than fmemopen and xdrstdio_create

@dwcaress
Copy link
Owner

dwcaress commented Feb 4, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants