Mock API: special case the SetErrorCallback procs.

Also add a suppression for these procs in wiretests, unless we are
specifically testing them.
diff --git a/generator/templates/mock_api.h b/generator/templates/mock_api.h
index feaaf8f..e5c70f8 100644
--- a/generator/templates/mock_api.h
+++ b/generator/templates/mock_api.h
@@ -18,18 +18,25 @@
 #include <gmock/gmock.h>
 #include <nxt/nxt.h>
 
+// An abstract base class representing a proc table so that API calls can be mocked. Most API calls
+// are directly represented by a delete virtual method but others need minimal state tracking to be
+// useful as mocks.
 class ProcTableAsClass {
     public:
         virtual ~ProcTableAsClass();
 
         void GetProcTableAndDevice(nxtProcTable* table, nxtDevice* device);
 
+        // Creates an object that can be returned by a mocked call as in WillOnce(Return(foo)).
+        // It returns an object of the write type that isn't equal to any previously returned object.
+        // Otherwise some mock expectation could be triggered by two different objects having the same
+        // value.
         {% for type in by_category["object"] %}
             {{as_cType(type.name)}} GetNew{{type.name.CamelCase()}}();
         {% endfor %}
 
         {% for type in by_category["object"] %}
-            {% for method in native_methods(type) if len(method.arguments) < 10 %}
+            {% for method in type.methods if len(method.arguments) < 10 %}
                 virtual {{as_cType(method.return_type.name)}} {{as_MethodSuffix(type.name, method.name)}}(
                     {{-as_cType(type.name)}} {{as_varName(type.name)}}
                     {%- for arg in method.arguments -%}
@@ -37,17 +44,39 @@
                     {%- endfor -%}
                 ) = 0;
             {% endfor %}
+            virtual void {{as_MethodSuffix(type.name, Name("reference"))}}({{as_cType(type.name)}} self) = 0;
+            virtual void {{as_MethodSuffix(type.name, Name("release"))}}({{as_cType(type.name)}} self) = 0;
 
+            // Stores callback and userdata and calls OnBuilderSetErrorCallback
+            {% if type.is_builder %}
+                void {{as_MethodSuffix(type.name, Name("set error callback"))}}({{as_cType(type.name)}} self, nxtBuilderErrorCallback callback, nxtCallbackUserdata userdata1, nxtCallbackUserdata userdata2);
+            {% endif %}
         {% endfor %}
 
+        // Stores callback and userdata and calls OnDeviceSetErrorCallback
+        void DeviceSetErrorCallback(nxtDevice self, nxtDeviceErrorCallback callback, nxtCallbackUserdata userdata);
+
+        // Special cased mockable methods
+        virtual void OnDeviceSetErrorCallback(nxtDevice device, nxtDeviceErrorCallback callback, nxtCallbackUserdata userdata) = 0;
+        virtual void OnBuilderSetErrorCallback(nxtBufferBuilder builder, nxtBuilderErrorCallback callback, nxtCallbackUserdata userdata1, nxtCallbackUserdata userdata2) = 0;
+
+        struct Object {
+            ProcTableAsClass* procs = nullptr;
+            nxtDeviceErrorCallback deviceErrorCallback = nullptr;
+            nxtBuilderErrorCallback builderErrorCallback = nullptr;
+            nxtCallbackUserdata userdata1 = 0;
+            nxtCallbackUserdata userdata2 = 0;
+        };
+
     private:
-        std::vector<ProcTableAsClass**> selfPtrs;
+        // Remembers the values returned by GetNew* so they can be freed.
+        std::vector<std::unique_ptr<Object>> objects;
 };
 
 class MockProcTable : public ProcTableAsClass {
     public:
         {% for type in by_category["object"] %}
-            {% for method in native_methods(type) if len(method.arguments) < 10 %}
+            {% for method in type.methods if len(method.arguments) < 10 %}
                 MOCK_METHOD{{len(method.arguments) + 1}}(
                     {{-as_MethodSuffix(type.name, method.name)}},
                     {{as_cType(method.return_type.name)}}(
@@ -58,7 +87,12 @@
                     ));
             {% endfor %}
 
+            MOCK_METHOD1({{as_MethodSuffix(type.name, Name("reference"))}}, void({{as_cType(type.name)}} self));
+            MOCK_METHOD1({{as_MethodSuffix(type.name, Name("release"))}}, void({{as_cType(type.name)}} self));
         {% endfor %}
+
+        MOCK_METHOD3(OnDeviceSetErrorCallback, void(nxtDevice device, nxtDeviceErrorCallback callback, nxtCallbackUserdata userdata));
+        MOCK_METHOD4(OnBuilderSetErrorCallback, void(nxtBufferBuilder builder, nxtBuilderErrorCallback callback, nxtCallbackUserdata userdata1, nxtCallbackUserdata userdata2));
 };
 
 #endif // MOCK_NXT_H