From 78a46fee71e7a1de455475cc8d37defcd6996839 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 2 Oct 2020 14:46:50 -0400 Subject: [PATCH] added mock script and header --- mocks.h | 6 +++++ tools/mock.rb | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 mocks.h create mode 100755 tools/mock.rb diff --git a/mocks.h b/mocks.h new file mode 100644 index 0000000..514163d --- /dev/null +++ b/mocks.h @@ -0,0 +1,6 @@ +#include +#include +#include + +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 index 0000000..2d8b649 --- /dev/null +++ b/tools/mock.rb @@ -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 -- 2.54.0