]> git.mdlowis.com Git - proto/aos.git/commitdiff
added mock script and header
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 2 Oct 2020 18:46:50 +0000 (14:46 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 2 Oct 2020 18:46:50 +0000 (14:46 -0400)
mocks.h [new file with mode: 0644]
tools/mock.rb [new file with mode: 0755]

diff --git a/mocks.h b/mocks.h
new file mode 100644 (file)
index 0000000..514163d
--- /dev/null
+++ b/mocks.h
@@ -0,0 +1,6 @@
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xft/Xft.h>
+
+void XSetForeground(Display* display, GC gc, unsigned long foreground);
+void XFillRectangle(Display* display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height);
diff --git a/tools/mock.rb b/tools/mock.rb
new file mode 100755 (executable)
index 0000000..2d8b649
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/env ruby
+
+HEADER = <<-eos
+
+typedef struct {
+    char* name;
+    int ndata;
+    char data[];
+} MockValue_T;
+
+typedef struct {
+    char* name;
+    MockValue_T* retval;
+    int nvalues;
+    MockValue_T* values[];
+} MockCall_T;
+
+#ifndef MAX_CALLS
+#define MAX_CALLS 256
+#endif
+
+int CurrentExpected = 0;
+int CurrentCall = 0;
+MockCall_T* ExpectedCalls[MAX_CALLS];
+MockCall_T* ActualCalls[MAX_CALLS];
+
+void MockInit(void)
+{
+    CurrentExpected = 0;
+    CurrentCall = 0;
+}
+
+/* REGISTER MOCK CALL */
+/* allocate call structure with N values */
+/* foreach arg */
+    /* allocate named value structure */
+    /* initialize  named value structure */
+    /* assign named value structure to slot in mock call */
+/* if call returns non-void */
+    /* allocate value structure */
+    /* initialize  value structure */
+    /* assign value structure to slot in mock call */
+
+eos
+
+def parse_args(args)
+  args.map do |a|
+    a = a.match(/(.*) ([_a-zA-Z0-9]+)$/)
+    { type: a[1], name: a[2] }
+  end
+end
+
+def genmock(name, args, rettype)
+  args = args.map {|a| "#{a[:type]} #{a[:name]}" }
+  puts "#{rettype} #{name}(#{args.join(", ")})\n{\n"
+  puts "}"
+  puts
+end
+
+File.read(ARGV[0]).each_line do |ln|
+  ln = ln.gsub(/(const|volatile)/,'')
+  if ln =~ /(.*) ([_a-zA-Z0-9]+)\((.*)\)/
+    rettype = $1
+    name = $2
+    args = $3.sub(/^ *([^ ]*) *$/, '\1')
+    args = (args == "void" ? [] : args.split(","))
+    args = parse_args(args)
+    genmock(name, args, rettype)
+  else
+    puts ln
+  end
+end
\ No newline at end of file