Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to mock interface classes #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/svmock_defines.svh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// MOCK CLASS MACROS
//-------------------

`define SVMOCK(MOCK,ORIGINAL=HAS_NO_PARENT) \
`define SVMOCK(MOCK,ORIGINAL=HAS_NO_PARENT,RELATION=extends) \
`define MOCK``_``ORIGINAL \
`define MOCK``_``RELATION \
`define MOCKTYPE MOCK``_``ORIGINAL \
`ifdef MOCK``_implements \
`define MOCKTYPE_HAS_NO_PARENT \
`endif \
`ifdef MOCK``_HAS_NO_PARENT \
`define MOCKTYPE_HAS_NO_PARENT \
class MOCK; \
`else \
class MOCK extends ORIGINAL; \
class MOCK RELATION ORIGINAL; \
`endif \
typedef MOCK PARENT; \
__mocker __mockers [$]; \
Expand Down
13 changes: 13 additions & 0 deletions test/mocks/mock_interface_class.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
interface class some_interface_class;

pure virtual function void vfunc0;

endclass



`SVMOCK(mock_interface_class, some_interface_class, implements)

`SVMOCK_VFUNC0(vfunc0)

`SVMOCK_END
80 changes: 80 additions & 0 deletions test/ut/inteface_class_unit_test.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
`include "svunit_defines.svh"
`include "svmock_defines.svh"

import ut_pkg::*;

module interface_class_unit_test;
import svunit_pkg::svunit_testcase;

string name = "interface_class_ut";
svunit_testcase svunit_ut;


//===================================
// This is the UUT that we're
// running the Unit Tests on
//===================================
mock_interface_class ut;


//===================================
// Build
//===================================
function void build();
svunit_ut = new(name);

ut = new(/* New arguments if needed */);
endfunction


//===================================
// Setup for running the Unit Tests
//===================================
task setup();
svunit_ut.setup();
/* Place Setup Code Here */

ut.clear();
endtask


//===================================
// Here we deconstruct anything we
// need after running the Unit Tests
//===================================
task teardown();
svunit_ut.teardown();
/* Place Teardown Code Here */

endtask


//===================================
// All tests are defined between the
// SVUNIT_TESTS_BEGIN/END macros
//
// Each individual test must be
// defined between `SVTEST(_NAME_)
// `SVTEST_END
//
// i.e.
// `SVTEST(mytest)
// <test code>
// `SVTEST_END
//===================================
`SVUNIT_TESTS_BEGIN

//-----------
// Functions
//-----------

`SVTEST(vfunc0)
`EXPECT_CALL(ut, vfunc0).exactly(1);

ut.vfunc0();
`FAIL_UNLESS(ut.verify());
`SVTEST_END

`SVUNIT_TESTS_END

endmodule
1 change: 1 addition & 0 deletions test/ut/ut_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ package ut_pkg;
`include "mock_call.sv"
`include "mock_second_no_parent.sv"
`include "mock_second.sv"
`include "mock_interface_class.sv"
endpackage