-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new modifier to class methods that hide base class methods
- Loading branch information
Showing
9 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "girtest-method-hiding.h" | ||
|
||
/** | ||
* GirTestMethodHidingBase: | ||
* | ||
* Base class for testing subclasses with method names that are the same as a parent class method | ||
*/ | ||
|
||
G_DEFINE_TYPE(GirTestMethodHidingBase, girtest_method_hiding_base, G_TYPE_OBJECT) | ||
|
||
static void | ||
girtest_method_hiding_base_init(GirTestMethodHidingBase *value) | ||
{ | ||
} | ||
|
||
static void | ||
girtest_method_hiding_base_class_init(GirTestMethodHidingBaseClass *class) | ||
{ | ||
} | ||
|
||
gchar * | ||
girtest_method_hiding_base_to_string(GirTestMethodHidingBase *instance) | ||
{ | ||
return g_strdup("New to_string"); | ||
} | ||
|
||
gchar * | ||
girtest_method_hiding_base_custom_string(GirTestMethodHidingBase *instance) | ||
{ | ||
return g_strdup("Base class custom string"); | ||
} | ||
|
||
/** | ||
* GirTestMethodHidingSubclass: | ||
* | ||
* Subclass for testing method names that are the same as a parent class method | ||
*/ | ||
|
||
struct _GirTestMethodHidingSubclass | ||
{ | ||
GirTestMethodHidingBase parent_instance; | ||
}; | ||
|
||
G_DEFINE_TYPE(GirTestMethodHidingSubclass, girtest_method_hiding_subclass, GIRTEST_TYPE_METHOD_HIDING_BASE) | ||
|
||
static void | ||
girtest_method_hiding_subclass_init(GirTestMethodHidingSubclass *value) | ||
{ | ||
} | ||
|
||
static void | ||
girtest_method_hiding_subclass_class_init(GirTestMethodHidingSubclassClass *class) | ||
{ | ||
} | ||
|
||
/** | ||
* girtest_method_hiding_subclass_new: | ||
* | ||
* Creates a new `GirTestMethodHidingSubclass`. | ||
* | ||
* Returns: The newly created `MethodHidingSubclass`. | ||
*/ | ||
GirTestMethodHidingSubclass* | ||
girtest_method_hiding_subclass_new(void) | ||
{ | ||
return g_object_new (GIRTEST_TYPE_METHOD_HIDING_SUBCLASS, NULL); | ||
} | ||
|
||
gchar * | ||
girtest_method_hiding_subclass_custom_string(GirTestMethodHidingSubclass *instance) | ||
{ | ||
return g_strdup("Subclass custom string"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <glib-object.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define GIRTEST_TYPE_METHOD_HIDING_BASE girtest_method_hiding_base_get_type() | ||
G_DECLARE_DERIVABLE_TYPE(GirTestMethodHidingBase, girtest_method_hiding_base, GIRTEST, METHOD_HIDING_BASE, GObject) | ||
|
||
struct _GirTestMethodHidingBaseClass | ||
{ | ||
GObjectClass parent_class; | ||
}; | ||
|
||
gchar * | ||
girtest_method_hiding_base_to_string(GirTestMethodHidingBase *instance); | ||
|
||
gchar * | ||
girtest_method_hiding_base_custom_string(GirTestMethodHidingBase *instance); | ||
|
||
#define GIRTEST_TYPE_METHOD_HIDING_SUBCLASS girtest_method_hiding_subclass_get_type() | ||
G_DECLARE_FINAL_TYPE(GirTestMethodHidingSubclass, girtest_method_hiding_subclass, GIRTEST, METHOD_HIDING_SUBCLASS, GirTestMethodHidingBase) | ||
|
||
struct _GirTestMethodHidingSubclassClass | ||
{ | ||
GirTestMethodHidingBaseClass parent_class; | ||
}; | ||
|
||
GirTestMethodHidingSubclass* | ||
girtest_method_hiding_subclass_new(void); | ||
|
||
gchar * | ||
girtest_method_hiding_subclass_custom_string(GirTestMethodHidingSubclass *instance); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GirTest.Tests; | ||
|
||
[TestClass, TestCategory("BindingTest")] | ||
public class MethodHidingTest : Test | ||
{ | ||
[TestMethod] | ||
public void CanCallNewToStringMethod() | ||
{ | ||
var instance = MethodHidingSubclass.New(); | ||
instance.ToString().Should().Be("New to_string"); | ||
} | ||
|
||
[TestMethod] | ||
public void CanCallObjectToStringMethod() | ||
{ | ||
var instance = MethodHidingSubclass.New(); | ||
var asObj = (object) instance; | ||
asObj.ToString().Should().Contain("MethodHidingSubclass"); | ||
} | ||
|
||
[TestMethod] | ||
public void CanCallNewMethodOnSubclass() | ||
{ | ||
var instance = MethodHidingSubclass.New(); | ||
instance.CustomString().Should().Be("Subclass custom string"); | ||
} | ||
|
||
[TestMethod] | ||
public void CanCallNewMethodFromBaseClass() | ||
{ | ||
var instance = MethodHidingSubclass.New(); | ||
var asBase = ((MethodHidingBase) instance); | ||
asBase.CustomString().Should().Be("Base class custom string"); | ||
} | ||
} |