Giter Site home page Giter Site logo

simply's People

Contributors

olegsych avatar

Stargazers

 avatar

Watchers

 avatar

simply's Issues

assert::null and assert::not_null template functions

template <typename T> void assert::null(const T* actual);
template <typename T> void assert::not_null(const T* actual);

These will replace the Assert::IsNull and Assert::IsNotNull functions in VSTest. The main challenge as in #1, is creating a descriptive representation of T* for the assertion failure message. In addition to that, including type name and physical address may be useful.

assert::true(int) and assert::false(int) functions

void assert::true(int actual);
void assert::false(int actual);

These are similar to standard true(bool) and false(bool) from #2, but for C-style Boolean values #define TRUE 1 and #define FALSE 0. They will allow writing semantic assertions like

assert::true(FALSE)

instead of

assert::equal(TRUE, FALSE);

and include terms TRUE and FALSE in assertion messages instead of the literal 1 and 0.

assert::dynamic_cast<t>(instance)

Replace asserts like this:

assert::not_null(dynamic_cast<foo*>(bar));

with semantic asserts like this:

foo* f = assert::dynamic_cast<foo*>(bar);
// more asserts on f;

Testing GUID values

I currently have to use Assert::IsTrue to test equality of GUID values, because they are not convertible to string.

Assert::IsTrue(clsid == __uuidof(factory));

assert::equal and assert::not_equal template functions

template<typename T> void assert::equal(const T& expected, const T& actual);
template<typename T> void assert::not_equal(const T& not_expected, const T& actual);

This will replace the Assert::AreEqual(const T&, const T&) and Assert::AreNotEqual(const T&, const T&) methods in VSTest and will provide better assertion failure messages. The main challenge is converting values of template type T to string. VSTest asks you to provide a custom ToString method:

namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework
{
  // User should provide a specialization of below ToString() template to use equality asserts in test code.
  // std::wstring ToString(const Q& q) is used for converting type Q in  user readable std::wstring value. 
  // Converted value is emitted in Assert failure message. Specialization for basic types has been provided below.
  template <typename Q> static std::wstring ToString(const Q& q) { static_assert(false, "Test writer must define specialization of ToString<const Q& q> for your class "__FUNCSIG__"."); }
}}}

There has to be a better way. Things to consider:

  • Many custom types supply ostream& operator<< (ostream& os, const T& value) that could be used to write a value to a string stream
  • to_string and to_wstring methods for a number of types are available in the STL

TODO

  • is_equal for c-style strings
  • is_equal for numeric values to avoid having to specify type explicitly

Implement equality operators in com_ptr

To simplify implementation of equality operators in consuming types, for example

struct foo 
{
    com_ptr<bar> baz;
    bool operator==(const foo& other)
    {
        return baz == other.baz;
    }
}

instead of

buz.get() == other.baz.get();

Simplify nullptr checking in com_ptr

The STL smart pointers in <memory> support the following style of null checking

void foo (unique_ptr<int> bar)
{
  if (bar)
  {
    // use bar
  }
}

It would be nice to allow similar coding style for com_ptr in addition to this

void foo (com_ptr<int> bar)
{
  if (bar.get())
  {
    // use bar
  }
}

I don't know exactly how the STL are implemented. This possibly requires implementing operator bool() and operator !().

assert::empty(string) template function

A semantic assertion to replace low-level assertions for C++ strings:

std::string s;
Assert::AreEqual<size_t>(0, s.length());

and C strings:

char* s;
Assert::AreEqual<size_t>(0, strlen(s));

with clean, high-level

assert::empty(s);

which includes actual content of the string in the failure message in addition to the string length.

The new method should be defined in assert/string.h and handle the generic C++ string classes and both char* and wchar_t* C++ strings, similar to the existing assert::find method.

Move type_name from utility to assert

type_name is implemented in the simply.utility package and currently used only by the simply.assert package. Without a package dependency, simply.assert fails to build when installed without simply.utility. It would be better to move the type_name to implementation of simply.assert where its used.

Testing HRESULT values

I use a lot of assertions like this:

Assert::AreEqual(E_INVALIDARG, sut->QueryInterface(IID_IUnknown, nullptr));

which produce meaningless assertion messages where HRESULT values appear as large numbers. I'd like to get meaningful assertion messages that at the very least include names, like E_NOTIMPL instead of their numeric values.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.