Skip to content

Commit aebfef3

Browse files
committed
Don't use assert shorthands in headers
Use DAEMON_ASSERT_xyz instead of ASSERT_xyz in headers, so that the headers are compatible with Googletest. Also document this requirement in Assert.h and provide a non-shorthand version of ASSERT_UNREACHABLE.
1 parent a831487 commit aebfef3

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

src/common/Assert.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242
* information to start debugging when the assert fires.
4343
*
4444
* In case of name clashes (with for example a testing library), you can define the
45-
* DAEMON_SKIP_ASSERT_SHORTHANDS to only define the DAEMON_ prefixed macros.
45+
* DAEMON_SKIP_ASSERT_SHORTHANDS to only define the DAEMON_ prefixed macros. Avoid using
46+
* the shorthands in header files, so that the headers can be included in tests.
4647
*
4748
* These asserts feature:
4849
* - Logging of the error with file, line and function information.
@@ -157,10 +158,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
157158
#define ASSERT_LE DAEMON_ASSERT_LE
158159
#define ASSERT_GT DAEMON_ASSERT_GT
159160
#define ASSERT_GE DAEMON_ASSERT_GE
161+
#define ASSERT_UNREACHABLE DAEMON_ASSERT_UNREACHABLE
160162
#endif
161163

162164
// You can put ASSERT_UNREACHABLE() in places that must never be reached.
163-
#define ASSERT_UNREACHABLE() DAEMON_ASSERT_CALLSITE(false, , false, "Unreachable code hit."); UNREACHABLE();
165+
#define DAEMON_ASSERT_UNREACHABLE() DAEMON_ASSERT_CALLSITE(false, , false, "Unreachable code hit."); UNREACHABLE();
164166

165167
#ifdef DAEMON_ASSERTS_ENABLED
166168
// This stuff is so that the ASSERT_cc variants can be used on objects that don't have a

src/common/Math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Math {
4040
template<typename T> inline WARN_UNUSED_RESULT
4141
T Clamp(T value, T min, T max)
4242
{
43-
ASSERT_LE(min, max);
43+
DAEMON_ASSERT_LE(min, max);
4444
if (!(value >= min))
4545
return min;
4646
if (!(value <= max))

src/engine/framework/Resource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace Resource {
6161
class Handle {
6262
public:
6363
Handle(std::shared_ptr<T> value, const Manager<T>* manager): value(value), manager(manager) {
64-
ASSERT(!!value); // Should not be null
64+
DAEMON_ASSERT(!!value); // Should not be null
6565
}
6666

6767
// Returns a pointer to the resource, or to the default value if the

src/engine/renderer/GLMemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class GLVAO {
234234
uint32_t ofs = 0;
235235
for ( const vertexAttributeSpec_t* spec = attrBegin; spec < attrEnd; spec++ ) {
236236
vboAttributeLayout_t& attr = attrs[spec->attrIndex];
237-
ASSERT_NQ( spec->numComponents, 0U );
237+
DAEMON_ASSERT_NQ( spec->numComponents, 0U );
238238
attr.componentType = spec->componentStorageType;
239239
if ( attr.componentType == GL_HALF_FLOAT && !glConfig.halfFloatVertexAvailable ) {
240240
attr.componentType = GL_FLOAT;

src/engine/renderer/gl_shader.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class GLUniformSampler : protected GLUniform {
495495
ShaderProgramDescriptor* p = _shader->GetProgram();
496496

497497
if ( _global || !_shader->UseMaterialSystem() ) {
498-
ASSERT_EQ( p, glState.currentProgram );
498+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
499499
}
500500

501501
return p->uniformLocations[_locationIndex];
@@ -574,7 +574,7 @@ class GLUniform1i : protected GLUniform
574574
ShaderProgramDescriptor *p = _shader->GetProgram();
575575

576576
if ( _global || !_shader->UseMaterialSystem() ) {
577-
ASSERT_EQ( p, glState.currentProgram );
577+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
578578
}
579579

580580
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -619,7 +619,7 @@ class GLUniform1ui : protected GLUniform {
619619
ShaderProgramDescriptor* p = _shader->GetProgram();
620620

621621
if ( _global || !_shader->UseMaterialSystem() ) {
622-
ASSERT_EQ( p, glState.currentProgram );
622+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
623623
}
624624

625625
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -663,7 +663,7 @@ class GLUniform1Bool : protected GLUniform {
663663
ShaderProgramDescriptor* p = _shader->GetProgram();
664664

665665
if ( _global || !_shader->UseMaterialSystem() ) {
666-
ASSERT_EQ( p, glState.currentProgram );
666+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
667667
}
668668

669669
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -710,7 +710,7 @@ class GLUniform1f : protected GLUniform
710710
ShaderProgramDescriptor *p = _shader->GetProgram();
711711

712712
if ( _global || !_shader->UseMaterialSystem() ) {
713-
ASSERT_EQ( p, glState.currentProgram );
713+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
714714
}
715715

716716
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -759,7 +759,7 @@ class GLUniform1fv : protected GLUniform
759759
ShaderProgramDescriptor *p = _shader->GetProgram();
760760

761761
if ( _global || !_shader->UseMaterialSystem() ) {
762-
ASSERT_EQ( p, glState.currentProgram );
762+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
763763
}
764764

765765
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -794,7 +794,7 @@ class GLUniform2f : protected GLUniform
794794
ShaderProgramDescriptor *p = _shader->GetProgram();
795795

796796
if ( _global || !_shader->UseMaterialSystem() ) {
797-
ASSERT_EQ( p, glState.currentProgram );
797+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
798798
}
799799

800800
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -846,7 +846,7 @@ class GLUniform3f : protected GLUniform
846846
ShaderProgramDescriptor *p = _shader->GetProgram();
847847

848848
if ( _global || !_shader->UseMaterialSystem() ) {
849-
ASSERT_EQ( p, glState.currentProgram );
849+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
850850
}
851851

852852
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -898,7 +898,7 @@ class GLUniform4f : protected GLUniform
898898
ShaderProgramDescriptor *p = _shader->GetProgram();
899899

900900
if ( _global || !_shader->UseMaterialSystem() ) {
901-
ASSERT_EQ( p, glState.currentProgram );
901+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
902902
}
903903

904904
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -947,7 +947,7 @@ class GLUniform4fv : protected GLUniform
947947
ShaderProgramDescriptor *p = _shader->GetProgram();
948948

949949
if ( _global || !_shader->UseMaterialSystem() ) {
950-
ASSERT_EQ( p, glState.currentProgram );
950+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
951951
}
952952

953953
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -982,7 +982,7 @@ class GLUniformMatrix4f : protected GLUniform
982982
ShaderProgramDescriptor *p = _shader->GetProgram();
983983

984984
if ( _global || !_shader->UseMaterialSystem() ) {
985-
ASSERT_EQ( p, glState.currentProgram );
985+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
986986
}
987987

988988
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1027,7 +1027,7 @@ class GLUniformMatrix32f : protected GLUniform {
10271027
ShaderProgramDescriptor* p = _shader->GetProgram();
10281028

10291029
if ( _global || !_shader->UseMaterialSystem() ) {
1030-
ASSERT_EQ( p, glState.currentProgram );
1030+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
10311031
}
10321032

10331033
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1065,7 +1065,7 @@ class GLUniformMatrix4fv : protected GLUniform
10651065
ShaderProgramDescriptor *p = _shader->GetProgram();
10661066

10671067
if ( _global || !_shader->UseMaterialSystem() ) {
1068-
ASSERT_EQ( p, glState.currentProgram );
1068+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
10691069
}
10701070

10711071
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1099,7 +1099,7 @@ class GLUniformMatrix34fv : protected GLUniform
10991099
ShaderProgramDescriptor *p = _shader->GetProgram();
11001100

11011101
if ( _global || !_shader->UseMaterialSystem() ) {
1102-
ASSERT_EQ( p, glState.currentProgram );
1102+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
11031103
}
11041104

11051105
if ( _shader->UseMaterialSystem() && !_global ) {
@@ -1155,7 +1155,7 @@ class GLUniformBlock
11551155
ShaderProgramDescriptor *p = _shader->GetProgram();
11561156
GLuint blockIndex = p->uniformBlockIndexes[_locationIndex];
11571157

1158-
ASSERT_EQ( p, glState.currentProgram );
1158+
DAEMON_ASSERT_EQ( p, glState.currentProgram );
11591159

11601160
if( blockIndex != GL_INVALID_INDEX ) {
11611161
glBindBufferBase( GL_UNIFORM_BUFFER, blockIndex, buffer );
@@ -2795,7 +2795,7 @@ static colorModulation_t ColorModulateColorGen(
27952795

27962796
if ( useMapLightFactor )
27972797
{
2798-
ASSERT_EQ( vertexOverbright, false );
2798+
DAEMON_ASSERT_EQ( vertexOverbright, false );
27992799
colorModulation.lightFactor = tr.mapLightFactor;
28002800
}
28012801

src/engine/renderer/tr_local.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,13 +2255,13 @@ enum
22552255
z = Math::Clamp( z, 0u, depth - 1 );
22562256
}
22572257

2258-
ASSERT_GE( x, 0u );
2259-
ASSERT_GE( y, 0u );
2260-
ASSERT_GE( z, 0u );
2258+
DAEMON_ASSERT_GE( x, 0u );
2259+
DAEMON_ASSERT_GE( y, 0u );
2260+
DAEMON_ASSERT_GE( z, 0u );
22612261

2262-
ASSERT_LT( x, width );
2263-
ASSERT_LT( y, height );
2264-
ASSERT_LT( z, depth );
2262+
DAEMON_ASSERT_LT( x, width );
2263+
DAEMON_ASSERT_LT( y, height );
2264+
DAEMON_ASSERT_LT( z, depth );
22652265

22662266
return grid[z * width * height + y * width + x];
22672267
}
@@ -2281,9 +2281,9 @@ enum
22812281
index = Math::Clamp( index, 0u, size - 1 );
22822282
}
22832283

2284-
ASSERT_GE( index, 0U );
2284+
DAEMON_ASSERT_GE( index, 0U );
22852285

2286-
ASSERT_LT( index, size );
2286+
DAEMON_ASSERT_LT( index, size );
22872287

22882288
return grid[index];
22892289
}

src/engine/sys/sys_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class EventBase {
4949

5050
template<typename T>
5151
const T& Cast() const {
52-
ASSERT_EQ(this->type, T::ClassType());
52+
DAEMON_ASSERT_EQ(this->type, T::ClassType());
5353
return *static_cast<const T*>(this);
5454
}
5555

0 commit comments

Comments
 (0)