summaryrefslogtreecommitdiffhomepage
path: root/mixlib/testsuite/mix_ins_t.c
blob: f643b47f1f6baa49d4eb3d3b452cb8e3aa0dae8e (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*----------------------- mix_ins_t.c -------------------------------
 * Tests for mix_ins.h
 *-------------------------------------------------------------------
** Copyright (C) 1999  Free Software Foundation, Inc.
**  
** 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 of the License, 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, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/

#include <stdlib.h>
#include <mix_ins.h>

/* Define VERBOSE_TEST if you want to get prints of the test */
/* #define VERBOSE_TEST */
#include "test.h"


int
main(int argc, const char**argv)
{
  mix_word_t words[6];
  mix_ins_t ins[3];
  guint k;
  
  INIT_TEST;
  
  g_print("\n...ok.\nTesting mix_ins_id_t properties...\n");
  for ( k = 0; k < mix_INVALID_INS; ++k )
    {
      mix_opcode_t c = mix_get_opcode_from_id(k);
      mix_fspec_t f = mix_get_fspec_from_id(k);
      mix_ins_id_t id = mix_get_ins_id(c,f);
      
      g_print("%02d:%s (%1d:%1d),  ",
	      c, mix_get_string_from_id(k), 
	      mix_fspec_left(f), mix_fspec_right(f));
      if ( (k+1)%3 == 0 ) g_print("\n");

      g_assert(id==k);
    }
  
  g_print("\n...ok.\nTesting mix_ins_t properties...\n");
  for ( k = 1; k < mix_INVALID_INS; ++k )
    {
      g_print("%d ",k);
      mix_ins_fill_from_id(ins[0], k);
      g_assert(mix_ins_id_from_ins(ins[0]) == k);
      ins[0].address = 0x0123;
      ins[0].index = mix_I2;
      words[2] = mix_ins_to_word(ins);
      g_assert(ins[0].address == mix_get_ins_address(words[2]));
      g_assert(ins[0].index == mix_get_ins_index(words[2]));
      g_assert(ins[0].fspec == mix_get_ins_fspec(words[2]));
      g_assert(ins[0].opcode == mix_get_ins_opcode(words[2]));
      g_assert(mix_word_to_ins(words[2],ins+1) == k);
      g_assert(ins[0].address == ins[1].address);
      g_assert(ins[0].index == ins[1].index);
      g_assert(ins[0].fspec == ins[1].fspec);
      g_assert(ins[0].opcode == ins[1].opcode);
    }
  
  g_print("\n...ok.\n");
  
  
  
  return EXIT_SUCCESS;
}