Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
3745d125
Commit
3745d125
authored
12 years ago
by
Richard Linden
Browse files
Options
Downloads
Patches
Plain Diff
SH-3406 WIP convert fast timers to lltrace system
added unit tests for LLUnit
parent
2facd637
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indra/llcommon/CMakeLists.txt
+1
-0
1 addition, 0 deletions
indra/llcommon/CMakeLists.txt
indra/llcommon/llunit.h
+20
-20
20 additions, 20 deletions
indra/llcommon/llunit.h
indra/llcommon/tests/llunit_test.cpp
+156
-0
156 additions, 0 deletions
indra/llcommon/tests/llunit_test.cpp
with
177 additions
and
20 deletions
indra/llcommon/CMakeLists.txt
+
1
−
0
View file @
3745d125
...
...
@@ -342,6 +342,7 @@ if (LL_TESTS)
LL_ADD_INTEGRATION_TEST
(
llstring
""
"
${
test_libs
}
"
)
LL_ADD_INTEGRATION_TEST
(
lltreeiterators
""
"
${
test_libs
}
"
)
LL_ADD_INTEGRATION_TEST
(
lluri
""
"
${
test_libs
}
"
)
LL_ADD_INTEGRATION_TEST
(
llunit
""
"
${
test_libs
}
"
)
LL_ADD_INTEGRATION_TEST
(
reflection
""
"
${
test_libs
}
"
)
LL_ADD_INTEGRATION_TEST
(
stringize
""
"
${
test_libs
}
"
)
LL_ADD_INTEGRATION_TEST
(
lleventdispatcher
""
"
${
test_libs
}
"
)
...
...
This diff is collapsed.
Click to expand it.
indra/llcommon/llunit.h
+
20
−
20
View file @
3745d125
...
...
@@ -334,7 +334,7 @@ struct HighestPrecisionType<LLUnit<UNIT_TYPE, STORAGE_TYPE> >
typedef
typename
HighestPrecisionType
<
STORAGE_TYPE
>::
type_t
type_t
;
};
#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name
, conversion_factor
) \
#define LL_DECLARE_DERIVED_UNIT(
conversion_factor,
base_unit_name, unit_name) \
struct unit_name \
{ \
typedef base_unit_name base_unit_t; \
...
...
@@ -358,30 +358,30 @@ struct ConversionFactor<base_unit_name, unit_name, STORAGE_TYPE> \
}
struct
Bytes
{
typedef
Bytes
base_unit_t
;
};
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Kilobytes
,
1024
);
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Megabytes
,
1024
*
1024
);
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Gigabytes
,
1024
*
1024
*
1024
);
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Bits
,
(
1.0
/
8.0
)
);
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Kilobits
,
(
1024
/
8
)
);
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Megabits
,
(
1024
/
8
)
);
LL_DECLARE_DERIVED_UNIT
(
Bytes
,
Gigabits
,
(
1024
*
1024
*
1024
/
8
));
LL_DECLARE_DERIVED_UNIT
(
1024
,
Bytes
,
Kilobytes
);
LL_DECLARE_DERIVED_UNIT
(
1024
*
1024
,
Bytes
,
Megabytes
);
LL_DECLARE_DERIVED_UNIT
(
1024
*
1024
*
1024
,
Bytes
,
Gigabytes
);
LL_DECLARE_DERIVED_UNIT
(
(
1.0
/
8.0
),
Bytes
,
Bits
);
LL_DECLARE_DERIVED_UNIT
(
(
1024
/
8
),
Bytes
,
Kilobits
);
LL_DECLARE_DERIVED_UNIT
(
(
1024
/
8
),
Bytes
,
Megabits
);
LL_DECLARE_DERIVED_UNIT
((
1024
*
1024
*
1024
/
8
)
,
Bytes
,
Gigabits
);
struct
Seconds
{
typedef
Seconds
base_unit_t
;
};
LL_DECLARE_DERIVED_UNIT
(
Seconds
,
Minutes
,
60
);
LL_DECLARE_DERIVED_UNIT
(
Seconds
,
Hours
,
60
*
60
);
LL_DECLARE_DERIVED_UNIT
(
Seconds
,
Milliseconds
,
(
1.0
/
1000.0
)
);
LL_DECLARE_DERIVED_UNIT
(
Seconds
,
Microseconds
,
(
1.0
/
(
1000000.0
))
);
LL_DECLARE_DERIVED_UNIT
(
Seconds
,
Nanoseconds
,
(
1.0
/
(
1000000000.0
)));
LL_DECLARE_DERIVED_UNIT
(
60
,
Seconds
,
Minutes
);
LL_DECLARE_DERIVED_UNIT
(
60
*
60
,
Seconds
,
Hours
);
LL_DECLARE_DERIVED_UNIT
(
(
1.0
/
1000.0
),
Seconds
,
Milliseconds
);
LL_DECLARE_DERIVED_UNIT
(
(
1.0
/
(
1000000.0
)),
Seconds
,
Microseconds
);
LL_DECLARE_DERIVED_UNIT
((
1.0
/
(
1000000000.0
))
,
Seconds
,
Nanoseconds
);
struct
Meters
{
typedef
Meters
base_unit_t
;
};
LL_DECLARE_DERIVED_UNIT
(
Meters
,
Kilometers
,
1000
);
LL_DECLARE_DERIVED_UNIT
(
Meters
,
Centimeters
,
(
1.0
/
100.0
)
);
LL_DECLARE_DERIVED_UNIT
(
Meters
,
Millimeters
,
(
1.0
/
1000.0
)
);
LL_DECLARE_DERIVED_UNIT
(
1000
,
Meters
,
Kilometers
);
LL_DECLARE_DERIVED_UNIT
(
(
1.0
/
100.0
),
Meters
,
Centimeters
);
LL_DECLARE_DERIVED_UNIT
(
(
1.0
/
1000.0
),
Meters
,
Millimeters
);
struct
Hertz
{
typedef
Hertz
base_unit_t
;
};
LL_DECLARE_DERIVED_UNIT
(
Hertz
,
Kilohertz
,
1000
);
LL_DECLARE_DERIVED_UNIT
(
Hertz
,
Megahertz
,
1000
*
1000
);
LL_DECLARE_DERIVED_UNIT
(
Hertz
,
Gigahertz
,
1000
*
1000
*
1000
);
}
LL_DECLARE_DERIVED_UNIT
(
1000
,
Hertz
,
Kilohertz
);
LL_DECLARE_DERIVED_UNIT
(
1000
*
1000
,
Hertz
,
Megahertz
);
LL_DECLARE_DERIVED_UNIT
(
1000
*
1000
*
1000
,
Hertz
,
Gigahertz
);
}
// namespace LLUnits
#endif // LL_LLUNIT_H
This diff is collapsed.
Click to expand it.
indra/llcommon/tests/llunit_test.cpp
0 → 100644
+
156
−
0
View file @
3745d125
/**
* @file llsingleton_test.cpp
* @date 2011-08-11
* @brief Unit test for the LLSingleton class
*
* $LicenseInfo:firstyear=2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2011, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include
"linden_common.h"
#include
"llunit.h"
#include
"../test/lltut.h"
namespace
LLUnits
{
// using powers of 2 to allow strict floating point equality
struct
Quatloos
{
typedef
Quatloos
base_unit_t
;
};
LL_DECLARE_DERIVED_UNIT
(
4
,
Quatloos
,
Latinum
);
LL_DECLARE_DERIVED_UNIT
((
1.0
/
4.0
),
Quatloos
,
Solari
);
}
namespace
tut
{
using
namespace
LLUnits
;
struct
units
{
};
typedef
test_group
<
units
>
units_t
;
typedef
units_t
::
object
units_object_t
;
tut
::
units_t
tut_singleton
(
"LLUnit"
);
// storage type conversions
template
<
>
template
<
>
void
units_object_t
::
test
<
1
>
()
{
LLUnit
<
Quatloos
,
F32
>
float_quatloos
;
ensure
(
float_quatloos
.
value
()
==
0.
f
);
LLUnit
<
Quatloos
,
S32
>
int_quatloos
;
ensure
(
int_quatloos
.
value
()
==
0
);
int_quatloos
=
42
;
ensure
(
int_quatloos
.
value
()
==
42
);
float_quatloos
=
int_quatloos
;
ensure
(
float_quatloos
.
value
()
==
42.
f
);
int_quatloos
=
float_quatloos
;
ensure
(
int_quatloos
.
value
()
==
42
);
float_quatloos
=
42.1
f
;
ensure
(
float_quatloos
==
42.1
f
);
int_quatloos
=
float_quatloos
;
ensure
(
int_quatloos
.
value
()
==
42
);
LLUnit
<
Quatloos
,
U32
>
unsigned_int_quatloos
(
float_quatloos
);
ensure
(
unsigned_int_quatloos
.
value
()
==
42
);
}
// conversions to/from base unit
template
<
>
template
<
>
void
units_object_t
::
test
<
2
>
()
{
LLUnit
<
Quatloos
,
F32
>
quatloos
(
1.
f
);
ensure
(
quatloos
.
value
()
==
1.
f
);
LLUnit
<
Latinum
,
F32
>
latinum_bars
(
quatloos
);
ensure
(
latinum_bars
.
value
()
==
1.
f
/
4.
f
);
latinum_bars
=
256
;
quatloos
=
latinum_bars
;
ensure
(
quatloos
.
value
()
==
1024
);
LLUnit
<
Solari
,
F32
>
solari
(
quatloos
);
ensure
(
solari
.
value
()
==
4096
);
}
// conversions across non-base units
template
<
>
template
<
>
void
units_object_t
::
test
<
3
>
()
{
LLUnit
<
Solari
,
F32
>
solari
=
4.
f
;
LLUnit
<
Latinum
,
F32
>
latinum_bars
=
solari
;
ensure
(
latinum_bars
.
value
()
==
0.25
f
);
}
// math operations
template
<
>
template
<
>
void
units_object_t
::
test
<
4
>
()
{
LLUnit
<
Quatloos
,
F32
>
quatloos
=
1.
f
;
quatloos
*=
4.
f
;
ensure
(
quatloos
.
value
()
==
4
);
quatloos
=
quatloos
*
2
;
ensure
(
quatloos
.
value
()
==
8
);
quatloos
=
2.
f
*
quatloos
;
ensure
(
quatloos
.
value
()
==
16
);
quatloos
+=
4.
f
;
ensure
(
quatloos
.
value
()
==
20
);
quatloos
+=
4
;
ensure
(
quatloos
.
value
()
==
24
);
quatloos
=
quatloos
+
4
;
ensure
(
quatloos
.
value
()
==
28
);
quatloos
=
4
+
quatloos
;
ensure
(
quatloos
.
value
()
==
32
);
quatloos
+=
quatloos
*
3
;
ensure
(
quatloos
.
value
()
==
128
);
quatloos
-=
quatloos
/
4
*
3
;
ensure
(
quatloos
.
value
()
==
32
);
quatloos
=
quatloos
-
8
;
ensure
(
quatloos
.
value
()
==
24
);
quatloos
-=
4
;
ensure
(
quatloos
.
value
()
==
20
);
quatloos
-=
4.
f
;
ensure
(
quatloos
.
value
()
==
16
);
quatloos
*=
2.
f
;
ensure
(
quatloos
.
value
()
==
32
);
quatloos
=
quatloos
*
2.
f
;
ensure
(
quatloos
.
value
()
==
64
);
quatloos
=
0.5
f
*
quatloos
;
ensure
(
quatloos
.
value
()
==
32
);
quatloos
/=
2.
f
;
ensure
(
quatloos
.
value
()
==
16
);
quatloos
=
quatloos
/
4
;
ensure
(
quatloos
.
value
()
==
4
);
F32
ratio
=
quatloos
/
LLUnit
<
Quatloos
,
F32
>
(
4.
f
);
ensure
(
ratio
==
1
);
quatloos
+=
LLUnit
<
Solari
,
F32
>
(
4.
f
);
ensure
(
quatloos
.
value
()
==
5
);
quatloos
-=
LLUnit
<
Latinum
,
F32
>
(
1.
f
);
ensure
(
quatloos
.
value
()
==
1
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment