// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// ----------------

/*
This test program is typically run indirectly, by the "wuffs test" or "wuffs
bench" commands. These commands take an optional "-mimic" flag to check that
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
giflib for GIF, libpng for PNG, etc.

To manually run this test:

for CC in clang gcc; do
  $CC -std=c99 -Wall -Werror cbor.c && ./a.out
  rm -f a.out
done

Each edition should print "PASS", amongst other information, and exit(0).

Add the "wuffs mimic cflags" (everything after the colon below) to the C
compiler flags (after the .c file) to run the mimic tests.

To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
the first "./a.out" with "./a.out -bench". Combine these changes with the
"wuffs mimic cflags" to run the mimic benchmarks.
*/

// !! wuffs mimic cflags: -DWUFFS_MIMIC

// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION

// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__CBOR

// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
// No mimic library.
#endif

// ---------------- Golden Tests

golden_test g_cbor_cbor_rfc_7049_examples_gt = {
    .want_filename = "test/data/cbor-rfc-7049-examples.tokens",
    .src_filename = "test/data/cbor-rfc-7049-examples.cbor",
};

// ---------------- CBOR Tests

const char*  //
test_wuffs_cbor_decode_interface() {
  CHECK_FOCUS(__func__);

  wuffs_cbor__decoder dec;
  CHECK_STATUS("initialize",
               wuffs_cbor__decoder__initialize(
                   &dec, sizeof dec, WUFFS_VERSION,
                   WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
  CHECK_STRING(do_test__wuffs_base__token_decoder(
      wuffs_cbor__decoder__upcast_as__wuffs_base__token_decoder(&dec),
      &g_cbor_cbor_rfc_7049_examples_gt));

  return NULL;
}

const char*  //
test_wuffs_cbor_decode_invalid() {
  CHECK_FOCUS(__func__);

  // The official suite of CBOR test vectors (collected in this repo as
  // test/data/cbor-rfc-7049-examples.cbor) contain valid examples.
  //
  // This suite contains invalid examples, which should be rejected.
  char* test_cases[] = {
      // Truncated (integer; major type 0) value.
      "\x18",
      // Tag in array, immediately before an 0xFF stop code. Some discussion is
      // at https://github.com/cbor/cbor.github.io/issues/65
      "\x9F\xD0\xFF",
      // Map with 1 element (an odd number).
      "\xA1\x01",
      // Map with 3 elements (an odd number).
      "\xBF\x01\x02\x03\xFF",
      // Tag in map, immediately before an 0xFF stop code. Some discussion is
      // at https://github.com/cbor/cbor.github.io/issues/65
      "\xBF\xD0\xFF",
      // Unused opcode.
      "\xFE",
  };

  int tc;
  for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
    wuffs_base__token tok_array[256];
    wuffs_base__token_buffer tok_buf =
        wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
            &tok_array[0], WUFFS_TESTLIB_ARRAY_SIZE(tok_array)));
    const bool closed = true;
    wuffs_base__io_buffer io_buf = wuffs_base__slice_u8__reader(
        wuffs_base__make_slice_u8((uint8_t*)(test_cases[tc]),
                                  strlen(test_cases[tc])),
        closed);

    wuffs_cbor__decoder dec;
    CHECK_STATUS("initialize",
                 wuffs_cbor__decoder__initialize(
                     &dec, sizeof dec, WUFFS_VERSION,
                     WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));

    wuffs_base__status status = wuffs_cbor__decoder__decode_tokens(
        &dec, &tok_buf, &io_buf, g_work_slice_u8);
    if (!wuffs_base__status__is_error(&status)) {
      RETURN_FAIL("tc=%d: have \"%s\", want an error", tc, status.repr);
    }
  }
  return NULL;
}

const char*  //
test_wuffs_cbor_decode_valid() {
  CHECK_FOCUS(__func__);

  // This suite contains valid examples, similar to the
  // test_wuffs_cbor_decode_invalid examples, but they should be accepted.
  char* test_cases[] = {
      // Map with 2 elements (an even number).
      "\xA1\x01\x02",
      // Tag immediately before an empty array.
      "\xD0\x9F\xFF",
      // Tag immediately before an empty map.
      "\xD0\xBF\xFF",
  };

  int tc;
  for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
    wuffs_base__token tok_array[256];
    wuffs_base__token_buffer tok_buf =
        wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
            &tok_array[0], WUFFS_TESTLIB_ARRAY_SIZE(tok_array)));
    const bool closed = true;
    wuffs_base__io_buffer io_buf = wuffs_base__slice_u8__reader(
        wuffs_base__make_slice_u8((uint8_t*)(test_cases[tc]),
                                  strlen(test_cases[tc])),
        closed);

    wuffs_cbor__decoder dec;
    CHECK_STATUS("initialize",
                 wuffs_cbor__decoder__initialize(
                     &dec, sizeof dec, WUFFS_VERSION,
                     WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));

    wuffs_base__status status = wuffs_cbor__decoder__decode_tokens(
        &dec, &tok_buf, &io_buf, g_work_slice_u8);
    if (!wuffs_base__status__is_ok(&status)) {
      RETURN_FAIL("tc=%d: have \"%s\", want no error", tc, status.repr);
    }
  }
  return NULL;
}

// ---------------- Mimic Tests

#ifdef WUFFS_MIMIC

// No mimic tests.

#endif  // WUFFS_MIMIC

// ---------------- CBOR Benches

// No CBOR benches.

// ---------------- Mimic Benches

#ifdef WUFFS_MIMIC

// No mimic benches.

#endif  // WUFFS_MIMIC

// ---------------- Manifest

proc g_tests[] = {

    test_wuffs_cbor_decode_interface,
    test_wuffs_cbor_decode_invalid,
    test_wuffs_cbor_decode_valid,

#ifdef WUFFS_MIMIC

// No mimic tests.

#endif  // WUFFS_MIMIC

    NULL,
};

proc g_benches[] = {

// No CBOR benches.

#ifdef WUFFS_MIMIC

// No mimic benches.

#endif  // WUFFS_MIMIC

    NULL,
};

int  //
main(int argc, char** argv) {
  g_proc_package_name = "std/cbor";
  return test_main(argc, argv, g_tests, g_benches);
}
