// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Mobius Forensic Toolkit
// Copyright (C) 2008,2009,2010,2011,2012,2013,2014,2015,2016 Eduardo Aguiar
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <mobius/unittest.h>
#include <mobius/data_decoder.h>
#include <mobius/io/file.h>

static void
testcase_data_decoder ()
{
  mobius::unittest test ("mobius::data_decoder");
  mobius::io::file f ("file:///tmp/unittest.dat");

  {
    auto writer = f.new_writer ();
    writer.write (mobius::bytearray {0x08,0x00,0x00,0x00});     // uint32_le = 8
    writer.write (mobius::bytearray {0x00,0x00,0x00,0x08});     // uint32_be = 8
    writer.write (mobius::bytearray {0xff,0xff});               // uint16_le = 65535
    writer.write ("abc");
    writer.write (mobius::bytearray {0, 0, 0, 0, 0, 0, 0, 0});  // nt_datetime 1601-01-01 00:00:00
  }

  auto reader = f.new_reader ();
  mobius::data_decoder decoder (reader);
  
  test.ASSERT_EQUAL (decoder.get_uint32_le (), 8);
  test.ASSERT_EQUAL (decoder.get_uint32_be (), 8);
  test.ASSERT_EQUAL (decoder.get_uint16_le (), 65535);
  test.ASSERT_EQUAL (decoder.get_string_by_size (3), "abc");
  test.ASSERT_EQUAL (decoder.get_nt_datetime (), mobius::datetime::datetime (1601, 1, 1, 0, 0, 0));

  test.end ();  
}

void
unittest_mobius ()
{
  testcase_data_decoder ();
}
