Skip to content
Closed
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
2 changes: 1 addition & 1 deletion bazel/rules/rules_score/examples/minimal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ unit(
component(
name = "MyComponent",
components = [":MyUnit"],
requirements = [],
requirements = [":feature_requirements"],
tests = [],
)

Expand Down
14 changes: 10 additions & 4 deletions bazel/rules/rules_score/examples/minimal/docs/class_design.puml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@

' Class diagram for MyUnit — internal design of the key-value store unit.

class MyUnit {
- store_ : std::unordered_map<std::string, std::string>
+ configure(key : const string&, value : const string&) : void
+ get(key : const string&) : string
namespace my_element {
namespace MyComponent {
namespace MyUnit {
class KeyValueStore {
- store_ : std::unordered_map<std::string, std::string>
+ configure(key : const string&, value : const string&) : void
+ get(key : const string&) : string
}
}
}
}

@enduml
15 changes: 12 additions & 3 deletions bazel/rules/rules_score/examples/minimal/src/my_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#include "src/my_unit.h"
#include "my_unit.h"

void MyUnit::configure(const std::string &key, const std::string &value) {
namespace my_element {
namespace MyComponent {
namespace MyUnit {

void KeyValueStore::configure(const std::string &key,
const std::string &value) {
store_[key] = value;
}

std::string MyUnit::get(const std::string &key) const {
std::string KeyValueStore::get(const std::string &key) const {
const auto it = store_.find(key);
return it != store_.end() ? it->second : "";
}

} // namespace MyUnit
} // namespace MyComponent
} // namespace my_element
10 changes: 9 additions & 1 deletion bazel/rules/rules_score/examples/minimal/src/my_unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#include <string>
#include <unordered_map>

class MyUnit {
namespace my_element {
namespace MyComponent {
namespace MyUnit {

class KeyValueStore {
public:
// trace: MinimalExample.FEAT_001
void configure(const std::string &key, const std::string &value);
Expand All @@ -27,3 +31,7 @@ class MyUnit {
private:
std::unordered_map<std::string, std::string> store_;
};

} // namespace MyUnit
} // namespace MyComponent
} // namespace my_element
12 changes: 6 additions & 6 deletions bazel/rules/rules_score/examples/minimal/src/my_unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

#include <gtest/gtest.h>

#include "src/my_unit.h"
#include "my_unit.h"

TEST(MyUnitTest, ConfigureAndGet) {
::testing::Test::RecordProperty(
"lobster-tracing", "MinimalExample.FEAT_001 MinimalExample.FEAT_002");
"lobster-tracing", "MinimalExample.FEAT_001,MinimalExample.FEAT_002");

::testing::Test::RecordProperty("given",
"a default-constructed MyUnit instance");
MyUnit unit{};
"a default-constructed MyUnit::KeyValueStore instance");
my_element::MyComponent::MyUnit::KeyValueStore unit{};

::testing::Test::RecordProperty(
"when",
Expand All @@ -36,8 +36,8 @@ TEST(MyUnitTest, MissingKeyReturnsEmpty) {
::testing::Test::RecordProperty("lobster-tracing", "MinimalExample.FEAT_002");

::testing::Test::RecordProperty("given",
"a default-constructed MyUnit instance");
MyUnit unit{};
"a default-constructed MyUnit::KeyValueStore instance");
my_element::MyComponent::MyUnit::KeyValueStore unit{};

::testing::Test::RecordProperty(
"when", "When get is called with a key that hasn't been configured yet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ component component_example <<component>> {

interface InternalInterface
unit_1 -l-( InternalInterface
unit_2 -r- InternalInterface
unit_2 )-r- InternalInterface
}

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@

@startuml unit_1_class_diagram

namespace unit_1 {
class Foo {
namespace safety_software_seooc_example {
namespace component_example {
interface InternalInterface <<interface>> {
{abstract} GetData(BindingType binding) : safety_software_seooc_example::component_example::Data*
}

+ GetNumber() : uint8_t
+ SetNumber(value : uint8_t) : void
namespace unit_1 {
class Foo {

+ GetNumber() : uint8_t
+ SetNumber(value : uint8_t) : void
}
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions bazel/rules/rules_score/examples/seooc/unit_1/foo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

#include "unit_1/foo.h"

namespace safety_software_seooc_example {
namespace component_example {
namespace unit_1 {

// trace: SampleComponent.REQ_COMP_001 SampleLibraryAPI.GetNumber
std::uint8_t Foo::GetNumber() const { return 42u; }

} // namespace unit_1
} // namespace component_example
} // namespace safety_software_seooc_example
12 changes: 12 additions & 0 deletions bazel/rules/rules_score/examples/seooc/unit_1/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

#include <cstdint>

namespace safety_software_seooc_example {
namespace component_example {
struct BindingType;
struct Data;

class InternalInterface {
public:
virtual Data *GetData(BindingType binding) = 0;
};

namespace unit_1 {

// trace: SampleComponent.REQ_COMP_002
Expand All @@ -28,5 +38,7 @@ class Foo final {
};

} // namespace unit_1
} // namespace component_example
} // namespace safety_software_seooc_example

#endif // FOO_H
2 changes: 2 additions & 0 deletions bazel/rules/rules_score/examples/seooc/unit_1/foo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <type_traits>

namespace unit_1 = safety_software_seooc_example::component_example::unit_1;

TEST(Foo, GetNumber) {
::testing::Test::RecordProperty("lobster-tracing",
"SampleComponent.REQ_COMP_001");
Expand Down
7 changes: 6 additions & 1 deletion bazel/rules/rules_score/examples/seooc/unit_2/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ namespace {
std::uint8_t kExpectedNumber = 42u;
}

namespace safety_software_seooc_example {
namespace component_example {
namespace unit_2 {

// trace: SampleComponent.REQ_COMP_004 SampleComponent.REQ_COMP_005
Bar::Bar(std::unique_ptr<unit_1::Foo> foo) : foo_{std::move(foo)} {}
Bar::Bar(std::unique_ptr<safety_software_seooc_example::component_example::unit_1::Foo> foo)
: foo_{std::move(foo)} {}

// trace: SampleComponent.REQ_COMP_003
bool Bar::AssertNumber() const {
assert(foo_ != nullptr);
return foo_->GetNumber() == kExpectedNumber;
}
} // namespace unit_2
} // namespace component_example
} // namespace safety_software_seooc_example
8 changes: 6 additions & 2 deletions bazel/rules/rules_score/examples/seooc/unit_2/bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
#include <cstdint>
#include <memory>

namespace safety_software_seooc_example {
namespace component_example {
namespace unit_2 {

// trace: SampleComponent.REQ_COMP_003 SampleComponent.REQ_COMP_004
// SampleComponent.REQ_COMP_005
class Bar final {
public:
explicit Bar(std::unique_ptr<unit_1::Foo> foo);
explicit Bar(std::unique_ptr<safety_software_seooc_example::component_example::unit_1::Foo> foo);
bool AssertNumber() const;

private:
std::unique_ptr<unit_1::Foo> foo_;
std::unique_ptr<safety_software_seooc_example::component_example::unit_1::Foo> foo_;
};

} // namespace unit_2
} // namespace component_example
} // namespace safety_software_seooc_example

#endif // BAR_H
3 changes: 3 additions & 0 deletions bazel/rules/rules_score/examples/seooc/unit_2/bar_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include <gtest/gtest.h>

namespace unit_1 = safety_software_seooc_example::component_example::unit_1;
namespace unit_2 = safety_software_seooc_example::component_example::unit_2;

TEST(Bar, AssertNumber) {
::testing::Test::RecordProperty(
"lobster-tracing", "SampleComponent.REQ_COMP_003,SampleComponent.REQ_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@

@startuml unit_2_class_diagram

' Detail of `Bar`. No namespace: the declaration matches the bodyless `Bar` of
' unit_2_overview.puml (name, element type and stereotype) and is anchored onto
' `unit_2`.
class Bar <<final>> {
--
- foo_ : unique_ptr<unit_1::Foo>
--
+ Bar(foo : unique_ptr<unit_1::Foo>)
+ AssertNumber() : bool
' Detail of Bar; Foo and the uses relationship are declared in
' unit_2_overview.puml.
namespace safety_software_seooc_example {
namespace component_example {
namespace unit_2 {
class Bar <<final>> {
--
- foo_ : unique_ptr<safety_software_seooc_example::component_example::unit_1::Foo>
--
+ Bar(foo : unique_ptr<safety_software_seooc_example::component_example::unit_1::Foo>)
+ AssertNumber() : bool
}
}
}
}

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
' All classes are references (no body); `Bar` is elaborated in
' unit_2_class_diagram.puml, `Foo` is owned and elaborated by unit_1.

namespace unit_1 {
class Foo <<final>>
}
namespace safety_software_seooc_example {
namespace component_example {
namespace unit_1 {
class Foo <<final>>
}

namespace unit_2 {
class Bar <<final>>
namespace unit_2 {
class Bar <<final>>
}
}
}

Bar --> Foo : uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

@startuml unit_3_class_diagram

namespace unit_3 {
class Formatter <<final>> {
+ Format(foo : const unit_1::Foo &) : std::string
namespace safety_software_seooc_example {
namespace component_example {
namespace sub_component_example {
namespace unit_3 {
class Formatter <<final>> {
+ Format(foo : const safety_software_seooc_example::component_example::unit_1::Foo &) : std::string
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@

#include "unit_3/formatter.h"

namespace safety_software_seooc_example {
namespace component_example {
namespace sub_component_example {
namespace unit_3 {

// trace: SampleComponent.REQ_COMP_006
std::string Formatter::Format(const unit_1::Foo &foo) const {
std::string Formatter::Format(
const safety_software_seooc_example::component_example::unit_1::Foo &foo) const {
return std::to_string(foo.GetNumber());
}

} // namespace unit_3
} // namespace sub_component_example
} // namespace component_example
} // namespace safety_software_seooc_example
9 changes: 8 additions & 1 deletion bazel/rules/rules_score/examples/seooc/unit_3/formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@

#include <string>

namespace safety_software_seooc_example {
namespace component_example {
namespace sub_component_example {
namespace unit_3 {

class Formatter final {
public:
// trace: SampleComponent.REQ_COMP_006
std::string Format(const unit_1::Foo &foo) const;
std::string Format(
const safety_software_seooc_example::component_example::unit_1::Foo &foo) const;
};

} // namespace unit_3
} // namespace sub_component_example
} // namespace component_example
} // namespace safety_software_seooc_example

#endif // FORMATTER_H
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include <gtest/gtest.h>

namespace unit_1 = safety_software_seooc_example::component_example::unit_1;
namespace unit_3 = safety_software_seooc_example::component_example::sub_component_example::unit_3;

TEST(Formatter, Format) {
::testing::Test::RecordProperty("lobster-tracing",
"SampleComponent.REQ_COMP_006");
Expand Down
8 changes: 7 additions & 1 deletion bazel/rules/rules_score/examples/some_other_library/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ load(
"fault_trees",
"safety_analysis",
"unit",
"unit_design",
)

architectural_design(
Expand Down Expand Up @@ -71,12 +72,17 @@ unit(
name = "abc",
scope = ["//:__pkg__"],
tests = [],
unit_design = [],
unit_design = [":abc_design"],
implementation = [
":some_other_library",
],
)

unit_design(
name = "abc_design",
static = ["abc_class_design.puml"],
)

component(
name = "component_example",
components = [
Expand Down
Loading
Loading