diff demos/test/store_test.c @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents 6362d3854bb4
children
line wrap: on
line diff
--- a/demos/test/store_test.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/demos/test/store_test.c	Sun Dec 19 11:34:45 2004 +0000
@@ -1,43 +1,44 @@
 #include "test.h"
 
+/* Test store/load macros with offsets */
 int store_test(void)
 {
-  unsigned char buf[8];
-  unsigned long L;
-  ulong64 LL;
+  unsigned char buf[24];
+  unsigned long L, L1;
+  int y;
+  ulong64 LL, LL1;
 
   L = 0x12345678UL;
-  STORE32L (L, &buf[0]);
-  L = 0;
-  LOAD32L (L, &buf[0]);
-  if (L != 0x12345678UL) {
-    printf ("LOAD/STORE32 Little don't work");
-    return 1;
-  }
-  LL = CONST64 (0x01020304050607);
-  STORE64L (LL, &buf[0]);
-  LL = 0;
-  LOAD64L (LL, &buf[0])
-    if (LL != CONST64 (0x01020304050607)) {
-    printf ("LOAD/STORE64 Little don't work");
-    return 1;
+  for (y = 0; y < 4; y++) {
+      STORE32L(L, buf + y);
+      LOAD32L(L1, buf + y);
+      if (L1 != L) {
+         fprintf(stderr, "\n32L failed at offset %d\n", y);
+         return 1;
+      }
+      STORE32H(L, buf + y);
+      LOAD32H(L1, buf + y);
+      if (L1 != L) {
+         fprintf(stderr, "\n32H failed at offset %d\n", y);
+         return 1;
+      }
   }
 
-  L = 0x12345678UL;
-  STORE32H (L, &buf[0]);
-  L = 0;
-  LOAD32H (L, &buf[0]);
-  if (L != 0x12345678UL) {
-    printf ("LOAD/STORE32 High don't work, %08lx", L);
-    return 1;
+  LL = CONST64 (0x01020304050607);
+  for (y = 0; y < 8; y++) {
+      STORE64L(LL, buf + y);
+      LOAD64L(LL1, buf + y);
+      if (LL1 != LL) {
+         fprintf(stderr, "\n64L failed at offset %d\n", y);
+         return 1;
+      }
+      STORE64H(LL, buf + y);
+      LOAD64H(LL1, buf + y);
+      if (LL1 != LL) {
+         fprintf(stderr, "\n64H failed at offset %d\n", y);
+         return 1;
+      }
   }
-  LL = CONST64 (0x01020304050607);
-  STORE64H (LL, &buf[0]);
-  LL = 0;
-  LOAD64H (LL, &buf[0])
-    if (LL != CONST64 (0x01020304050607)) {
-    printf ("LOAD/STORE64 High don't work");
-    return 1;
-  }
+
   return 0;
 }