<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mocking Opaque Types</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112982/mocking-opaque-types</link><description>Hi guys , another question here regarding Cmock and opaque types . I am currently trying to mock a function with an argument that contains the type &amp;quot;struct bt _conn &amp;quot; . However when building this mock , I get the following error: 
 After doing some digging</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Jul 2024 08:38:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112982/mocking-opaque-types" /><item><title>RE: Mocking Opaque Types</title><link>https://devzone.nordicsemi.com/thread/494501?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2024 08:38:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c02f53e-aae3-4ca0-b9d0-f9d8581e1fa1</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello Jesse,&lt;/p&gt;
&lt;p&gt;Thanks for providing the update; it&amp;#39;s good to hear that you&amp;#39;ve made some progress. Let me know if I need to escalate this issue to get an expert opinion, as I am not an expert on this topic. Please note that there might be some delay in getting an update due to the summer vacation period in Norway.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mocking Opaque Types</title><link>https://devzone.nordicsemi.com/thread/494156?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2024 13:11:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe9865cd-01ac-4499-8327-862b5529044a</guid><dc:creator>Jesse_Carpenter</dc:creator><description>&lt;p&gt;I&amp;#39;ve come to a temporary solution by defining the struct bt_conn within my source file, with compiler tags around it so that this definition is only used when I&amp;#39;m testing. I have yet to actually test this, but it at least compiles for now.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#ifdef TESTING
typedef struct bt_conn {
    int dummy;
} bt_conn;
#endif&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mocking Opaque Types</title><link>https://devzone.nordicsemi.com/thread/493959?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 15:05:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb4456d6-6bea-4186-9bcd-8fc97f3c75b4</guid><dc:creator>Jesse_Carpenter</dc:creator><description>&lt;p&gt;I also came across &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/76986/unit-testing-and-mocking-in-nrf-connect-sdk"&gt;this post&lt;/a&gt;, but I cannot add a fake definition of bt_conn in the autogenerated cmock header that will exist across builds.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mocking Opaque Types</title><link>https://devzone.nordicsemi.com/thread/493940?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 13:58:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1ecf0eb-cfa8-4bb6-b4bc-4ed04a3fbbf8</guid><dc:creator>Jesse_Carpenter</dc:creator><description>&lt;p&gt;Hi &lt;span&gt;Abhijith,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So the actual function call already calls a pointer. Thats on me for not being specific enough. Here&amp;#39;s the function:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void on_sent(struct bt_conn *conn, void *user_data);
&lt;/pre&gt;&lt;br /&gt;I have many more functions that I&amp;#39;ll need to test later that also call bt_conn as a pointer.&lt;br /&gt;&lt;br /&gt;I tried defining the argument as not a pointer as well, but still get the same issue. When I try defining the type struct bt_conn within my test file, and even give it some meaningless content, the error still persists. When I brought this up on the discord, they suggested making my own mocks of all of the functions and even mocking the struct itself by hand, however I don&amp;#39;t believe this will allow me to continue using Unity they way that I already have been. If you could please escalate this ASAP I would greatly appreciate it.&lt;br /&gt;-Jesse&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mocking Opaque Types</title><link>https://devzone.nordicsemi.com/thread/493840?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 09:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d00d8ff9-b945-4c77-a2a9-bb4cafde1530</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry for the delay in responding. I&amp;#39;m also not very familiar with opaque types and Cmock. The log you uploaded indicates there was a build issue because the code attempted to determine the size of a type, const struct bt_conn, which was not fully defined at that point. This problem occurred in the mock function __cmock_on_sent generated by CMock. To potentially resolve issues related to incomplete type definitions, could you try using a pointer to &lt;strong&gt;struct bt_conn (struct bt_conn *conn)&lt;/strong&gt; instead of&lt;strong&gt; (struct bt_conn conn)&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;Please let me know if this solution works for you. Otherwise, I will escalate the issue internally to someone with more experience.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>